ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#164639 | #2909. number | larryzhong | 100 | 990ms | 2044kb | C++11 | 1.3kb | 2022-11-05 11:26:34 | 2022-11-05 13:02:45 |
answer
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int B = 1e5, M = 100;
int sigma[B], f[10][M][M];
ll pw[11];
int get(ll x) {
return sigma[x / B] + sigma[x % B];
}
void init() {
for (int i = 1; i < B; i++) {
sigma[i] = sigma[i / 10] + i % 10;
}
for (int i = pw[0] = 1; i <= 10; i++) {
pw[i] = 10 * pw[i - 1];
}
for (int i = 0; i < 10; i++) {
for (int j = 0; j < M; j++) {
for (int k = M - 1; ~k; k--) {
if (!i) {
int t = j + k + get(k);
f[i][j][k] = t >= M ? t - M : f[i][j][t];
} else {
f[i][j][k] = k;
for (int _ = 0; _ < 10 && j + _ < M; _++) {
f[i][j][k] = f[i - 1][j + _][f[i][j][k]];
}
}
}
}
}
}
void solve() {
ll x, y;
cin >> x >> y, y++;
ll a = x / M, c = x % M;
ll b = y / M, d = y % M;
int o = 0;
if (!a && b) {
a = 1, c = f[0][0][c];
}
while (a < b) {
while (a % pw[o + 1] == 0) o++;
if (a + pw[o] > b) break;
c = f[o][get(a)][c];
a += pw[o];
}
while (1) {
while (~o && a + pw[o] > b) o--;
if (!~o) break;
c = f[o][get(a)][c];
a += pw[o];
}
while (c < d) {
c += get(a * M + c);
}
cout << a * M + c << "\n";
}
int main() {
ios::sync_with_stdio(0), cin.tie(0);
int q;
cin >> q;
init();
while (q--) {
solve();
}
return 0;
}
详细
小提示:点击横条可展开更详细的信息
Subtask #1:
score: 20
Accepted
Test #1:
score: 20
Accepted
time: 163ms
memory: 2040kb
input:
500000 1 1 1 2 1 3 1 4 1 5 1 6 1 7 1 8 1 9 1 10 1 11 1 12 1 13 1 14 1 15 1 16 1 17 1 18 1 19 1 20 1 ...
output:
2 4 4 8 8 8 8 16 16 16 16 16 16 16 16 23 23 23 23 23 23 23 28 28 28 28 28 38 38 38 38 38 38 38 38 38...
result:
ok 500000 lines
Test #2:
score: 0
Accepted
time: 318ms
memory: 2044kb
input:
500000 92 99927 119 99453 481 99268 29 99908 267 99547 835 99500 955 99099 734 99774 306 99883 729 9...
output:
99941 99454 99274 99941 99555 99520 99112 99775 99900 99657 99978 100010 99545 99245 99775 99907 997...
result:
ok 500000 lines
Subtask #2:
score: 25
Accepted
Test #3:
score: 25
Accepted
time: 191ms
memory: 2044kb
input:
500000 1 1 1 2 1 3 1 4 1 5 1 6 1 7 1 8 1 9 1 10 1 11 1 12 1 13 1 14 1 15 1 16 1 17 1 18 1 19 1 20 1 ...
output:
2 4 4 8 8 8 8 16 16 16 16 16 16 16 16 23 23 23 23 23 23 23 28 28 28 28 28 38 38 38 38 38 38 38 38 38...
result:
ok 500000 lines
Subtask #3:
score: 25
Accepted
Test #4:
score: 25
Accepted
time: 3ms
memory: 2032kb
input:
50 4587480273 4587480273 428862505 500400481 6920415626 7358620174 7787875953 7787884613 4542304779 ...
output:
4587480321 500400482 7358620210 7787884620 4542307848 4676070172 909798356 3555627285 9508855574 511...
result:
ok 50 lines
Subtask #4:
score: 30
Accepted
Test #5:
score: 30
Accepted
time: 315ms
memory: 2044kb
input:
500000 1 1 1 2 1 3 1 4 1 5 1 6 1 7 1 8 1 9 1 10 1 11 1 12 1 13 1 14 1 15 1 16 1 17 1 18 1 19 1 20 1 ...
output:
2 4 4 8 8 8 8 16 16 16 16 16 16 16 16 23 23 23 23 23 23 23 28 28 28 28 28 38 38 38 38 38 38 38 38 38...
result:
ok 500000 lines