QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#84490 | #1875. Nein | magicduck | WA | 207ms | 3476kb | C++14 | 1.8kb | 2023-03-06 15:22:57 | 2023-03-06 15:24:44 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
template <typename T> inline void read(T &FF) {
int RR = 1; FF = 0; char CH = getchar();
for(; !isdigit(CH); CH = getchar()) if(CH == '-') RR = -RR;
for(; isdigit(CH); CH = getchar()) FF = FF * 10 + CH - 48;
FF *= RR;
}
inline void file(string str) {
freopen((str + ".in").c_str(), "r", stdin);
freopen((str + ".out").c_str(), "w", stdout);
}
const int N = 42;
LL g[N][N * 9];
void Add(LL &x, LL y) {
x += y; x = min(x, (LL)(2e18));
}
LL mul(LL x, LL y) {
return min((__int128)(2e18), (__int128)(x) * y);
}
void init() {
g[0][0] = 1;
for(int i = 1; i <= 40; i++)
for(int j = 0; j <= i * 8; j++)
for(int k = 0; k <= 8; k++)
if(k <= j) Add(g[i][j], g[i - 1][j - k]);
}
int k; LL n, f[N][N];
LL calc(LL x, int l) {
memset(f, 0, sizeof(f)); f[0][0] = 1;
for(int i = 1; i <= k; i++, x /= 10) {
const int len = (i <= l % k ? (l - 1) / k + 1 : l / k);
for(int j = 0; j <= 40; j++)
for(int k = (x - j + 10) % 10; k <= 320; k += 10)
Add(f[i][(j + k) / 10], mul(g[len][k], f[i - 1][j]));
}
x = min(x, 40LL); return f[k][x];
}
void print(__int128 x) {
if(x < 10) {
putchar('0' + x); return;
}
print(x / 10); putchar('0' + x % 10);
}
int main() {
//file("");
read(k), read(n); n++; init();
LL m = 1;
for(int i = 1; i <= k; i++) m = m * 10; m--;
LL s = 0; __int128 ans = 0;
for(int i = 37; i >= 1; i--) {
LL r = 1; __int128 G = 1;
for(int j = 1; j < i; j++) G = G * 10;
for(int j = 1; j < i; j++) r = (__int128)(r) * 10 % m;
for(int j = 0; j <= 8; j++) {
LL sum = 0;
for(int v = 0; v <= 20; v++)
Add(sum, calc(s + v * m, i - 1));
if(sum >= n) break;
n -= sum; ans += G; s = (s + m - r) % m;
}
}
ans /= m; print(ans); puts("");
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 5ms
memory: 3476kb
input:
1 1
output:
2
result:
ok answer is '2'
Test #2:
score: 0
Accepted
time: 5ms
memory: 3408kb
input:
1 8
output:
9
result:
ok answer is '9'
Test #3:
score: 0
Accepted
time: 1ms
memory: 3396kb
input:
1 9
output:
12
result:
ok answer is '12'
Test #4:
score: 0
Accepted
time: 5ms
memory: 3412kb
input:
1 10
output:
13
result:
ok answer is '13'
Test #5:
score: 0
Accepted
time: 30ms
memory: 3460kb
input:
5 1
output:
11112
result:
ok answer is '11112'
Test #6:
score: 0
Accepted
time: 31ms
memory: 3476kb
input:
5 84
output:
11235
result:
ok answer is '11235'
Test #7:
score: 0
Accepted
time: 28ms
memory: 3476kb
input:
5 668
output:
12345
result:
ok answer is '12345'
Test #8:
score: 0
Accepted
time: 30ms
memory: 3472kb
input:
5 733942
output:
2281488
result:
ok answer is '2281488'
Test #9:
score: -100
Wrong Answer
time: 207ms
memory: 3460kb
input:
18 528599760553218747
output:
9020128411283713843
result:
wrong answer expected '30725517742188427234', found '9020128411283713843'