QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#504677#9107. Zayin and Countuntitledtwo#AC ✓24ms3792kbC++201.2kb2024-08-04 14:43:012024-08-04 14:43:02

Judging History

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

  • [2024-08-04 14:43:02]
  • 评测
  • 测评结果:AC
  • 用时:24ms
  • 内存:3792kb
  • [2024-08-04 14:43:01]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
typedef __int128 ull;
bool a[11], b[11];
char s[100010], t[100010];
inline int geta(int u)
{
	int ans = 0;
	for(int i = 0; i < u; i++)
		ans += a[i];
	return ans;
}
inline int getb(int u)
{
	int ans = 0;
	for(int i = 0; i < 10; i++)
		if(b[i])
		{
			if(ans == u)
				return i;
			ans++;
		}
}
signed main()
{
	int T;
	scanf("%d", &T);
	while(T--)
	{
		int n = 0, m = 0;
		for(int i = 0; i < 10; i++)
			scanf("%d", &a[i]), n += a[i];
		for(int i = 0; i < 10; i++)
			scanf("%d", &b[i]), m += b[i];
		scanf("%s", s + 1);
		ull x = 1, pw = 1;
		int len = strlen(s + 1);
		for(int i = 1; i < len; i++)
		{
			x += (i == 1 || !a[0] ? n : n - 1) * pw;
			pw *= n;
		}
		for(int i = 1; i <= len; i++)
		{
			x += (geta(s[i] - '0') - (len != 1 && i == 1 && a[0] ? 1 : 0)) * pw;
			pw /= n;
		}
		pw = 1;
		int p = 1;
		while(true)
		{
			ull cnt = (p == 1 || !b[0] ? m : m - 1) * pw;
			if(x <= cnt)
				break;
			x -= cnt;
			pw *= m, p++;
		}
		for(int i = 1; i <= p; i++)
		{
			t[i] = getb((x - 1) / pw + (p != 1 && i == 1 && b[0] ? 1 : 0)) + '0';
			x = (x - 1) % pw + 1;
			pw /= m;
		}
		t[p + 1] = '\0';
		printf("%s\n", t + 1);
	}
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 24ms
memory: 3792kb

input:

10000
1 0 0 0 1 1 0 0 0 1
0 0 1 0 1 1 1 1 0 0
950595954440050004054505054050
1 0 0 0 1 1 1 1 0 0
1 1 1 0 1 0 0 0 1 1
45467007076660767550460064
1 1 1 1 0 0 0 1 0 0
1 1 0 1 1 0 1 0 0 1
23373171320213300170200722
0 0 0 0 1 1 1 0 1 0
0 0 1 0 0 1 0 1 1 1
558565664666565565558468668484
1 1 0 0 1 0 1 0 1 ...

output:

52755244567262766742575722
41990991999414091249949
101364364636933104003903
57558888789255872922852552
757222758857875785288225787822
761161760076076167101117776167
56666586555668686566656586856566686658
15611661611611111511116116661611616155
505885888775005550558080707878
3912911219633669993999199
...

result:

ok 10000 lines