QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#28362 | #1875. Nein | cdw | WA | 1ms | 3696kb | C++20 | 1.4kb | 2022-04-13 20:31:13 | 2022-04-29 09:41:06 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
typedef unsigned long long LL;
typedef __uint128_t LLL;
const int N = 360;
template<typename T>
void write(T x){
if(x >= 10) write(x / 10);
putchar(x % 10 + '0');
}
int k, B, ans[N]; LL n;
LLL pw[23], wys[23][200], f[23][23], M, now;
LLL solve(int len){
LLL rem = now, ans = 0;
for(int _ = 0;_ < B;++ _, rem += M){
memset(f, 0, sizeof f); **f = 1;
for(int i = 0;i < k;++ i){
int num = (len+k-i-1) / k;
for(int j = 0;j < B;++ j) if(f[i][j])
for(int nxt = 0;nxt < B;++ nxt){
int sum = nxt * 10 + rem / pw[i] % 10 - j;
if(sum >= 0 && sum <= 8 * num)
f[i+1][nxt] += f[i][j] * wys[num][sum];
}
}
ans += f[k][rem / pw[k]];
} return ans;
}
int main(){
ios::sync_with_stdio(false);
cin >> k >> n; pw[0] = wys[0][0] = 1;
for(int i = 0;i < k;++ i) pw[i+1] = pw[i] * 10;
for(int i = 0;i < 20;++ i)
for(int j = 0;j <= i*8;++ j)
for(int c = 0;c <= 8;++ c)
wys[i+1][j+c] += wys[i][j];
M = pw[k] - 1; B = 2 + 20 / k;
for(int i = B*k-1;~i;-- i)
for(ans[i] = 0;ans[i] < 9;++ ans[i]){
LLL c = solve(i);
if(n >= c) n -= c; else break;
if(now < pw[i%k]) now += M;
now -= pw[i%k];
}
LLL re = 0; bool fl = false;
for(int i = B*k-1;~i;-- i){
re = re * 10 + ans[i];
if(re >= M) fl = true;
if(fl) putchar(char(re / M + '0'));
re %= M;
} assert(!re);
}
詳細信息
Test #1:
score: 0
Wrong Answer
time: 1ms
memory: 3696kb
input:
1 1
output:
1000000000000000000002
result:
wrong answer expected '2', found '1000000000000000000002'