QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#686356#1875. Neinuser10086RE 13ms3996kbC++231.7kb2024-10-29 11:40:412024-10-29 11:40:42

Judging History

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

  • [2024-10-29 11:40:42]
  • 评测
  • 测评结果:RE
  • 用时:13ms
  • 内存:3996kb
  • [2024-10-29 11:40:41]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std;

const int N = 36;

#define int __int128

int f[N][N * 10];

void pre()
{
	f[0][0] = 1;
	for (int i = 0; i + 1 < N; i++) 
		for (int j = 0; j < N * 8; j++)
			if (f[i][j]) for (int k = 0; k <= 8; k++)
				assert(j + k < N * 8), f[i + 1][j + k] += f[i][j];
}

long long k, sz[N];
int pw[N];
long long x;

bool vis[N][N * 10];
int dp[N][N * 10];

int dfs(int tar, int cur, int c)
{
//	printf("dfs(%lld, %lld, %lld)\n", tar, cur, c);
	if (cur >= k) return c == tar;
	if (vis[cur][c]) return dp[cur][c];
	vis[cur][c] = true, dp[cur][c] = 0;
	for (int j = 0; j < N * 8; j++)
	{
		if (!f[sz[cur]][j] || (c + j) % 10 != tar % 10) continue;
//		printf("put %lld:\n", j);
		dp[cur][c] += f[sz[cur]][j] * dfs(tar / 10, cur + 1, (c + j) / 10);
	}
//	printf("dfs(%lld, %lld, %lld) = %lld\n", tar, cur, c, dp[cur][c]);
	return dp[cur][c];
}

signed main()
{
	cin >> k >> x; x++;
	pre();
	for (int i = 0; i <= N - 1; i++) sz[i % k]++;
	pw[0] = 1; for (int i = 1; i < N; i++) pw[i] = pw[i - 1] * 10;
	vector<int> sol;
	int cur = 0;
	for (int i = N - 1; i >= 0; i--)
	{
		for (int j = 0; ; j++)
		{
			assert(j <= 8);
			cur += j * pw[i % k], sz[i % k]--;
//			printf("i = %lld, j = %lld\n", i, j);
			int c = 0;
			for (int p = 0; p < N; p++)
			{
				int tar = p * (pw[k] - 1) - cur;
				if (tar < 0) continue;
				memset(vis, 0, sizeof vis);
				c += dfs(tar, 0, 0);
			}
//			printf("c = %lld\n", c);
			if (x <= c)
			{
				sol.push_back(j);
				break;
			}
			else x -= c, sz[i % k]++, cur -= j * pw[i % k];
		}
	}
	int tmp = 0; for (int x : sol) tmp = tmp * 10 + x;
//	cout << tmp << ' ' << (pw[k] - 1) << endl;
	cout << (long long)(tmp / (pw[k] - 1));
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 2ms
memory: 3736kb

input:

1 1

output:

2

result:

ok answer is '2'

Test #2:

score: 0
Accepted
time: 2ms
memory: 3996kb

input:

1 8

output:

9

result:

ok answer is '9'

Test #3:

score: 0
Accepted
time: 2ms
memory: 3804kb

input:

1 9

output:

12

result:

ok answer is '12'

Test #4:

score: 0
Accepted
time: 2ms
memory: 3832kb

input:

1 10

output:

13

result:

ok answer is '13'

Test #5:

score: 0
Accepted
time: 11ms
memory: 3752kb

input:

5 1

output:

11112

result:

ok answer is '11112'

Test #6:

score: 0
Accepted
time: 12ms
memory: 3972kb

input:

5 84

output:

11235

result:

ok answer is '11235'

Test #7:

score: 0
Accepted
time: 12ms
memory: 3784kb

input:

5 668

output:

12345

result:

ok answer is '12345'

Test #8:

score: 0
Accepted
time: 13ms
memory: 3848kb

input:

5 733942

output:

2281488

result:

ok answer is '2281488'

Test #9:

score: -100
Runtime Error

input:

18 528599760553218747

output:


result: