QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#28362#1875. NeincdwWA 1ms3696kbC++201.4kb2022-04-13 20:31:132022-04-29 09:41:06

Judging History

你现在查看的是最新测评结果

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2022-04-29 09:41:06]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3696kb
  • [2022-04-13 20:31:13]
  • 提交

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);
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 1ms
memory: 3696kb

input:

1 1

output:

1000000000000000000002

result:

wrong answer expected '2', found '1000000000000000000002'