QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#504934#9107. Zayin and Countikun#AC ✓15ms3584kbC++201.8kb2024-08-04 17:27:022024-08-04 17:27:02

Judging History

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

  • [2024-08-04 17:27:02]
  • 评测
  • 测评结果:AC
  • 用时:15ms
  • 内存:3584kb
  • [2024-08-04 17:27:02]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
#define endl '\n'
#define int unsigned long long
#define all(x) (x).begin(), (x).end()
#define ls id << 1
#define rs id << 1 | 1

using i128 = __int128_t;

void solve(){
	int ac = 0, bc = 0;
	vector<int>a(10), b(10), av(10), bv(10), ark(10), brk(10);
	for(int i = 0;i < 10;i++){
		cin >> a[i];
		if(a[i]){
			av[ac] = i;
			ark[i] = ac++;
		}
	}
	for(int i = 0;i < 10;i++){
		cin >> b[i];
		if(b[i]){
			bv[bc] = i;
			brk[i] = bc++;
		}
	}

	string s;
	cin >> s;
	for(auto &c : s) {
		c = ark[c-'0'] + '0';
	}
	vector<i128>pw(s.size());
	vector<i128>pre(s.size());
	pw[0] = 1;
	for(int i = 1;i < pw.size();i++){
		pw[i] = pw[i-1] * ac;
		pre[i] = pw[i] + pre[i-1];
	}


	i128 x = 0;
	if(a[0]){
		for(int i = 0;i < s.size();i++){
			x += pw[s.size()-i-1] * (s[i]-'0');
		}
		x++;
	}else{
		x += pre[s.size()-1];
		for(int i = 0;i < s.size();i++){
			x += (s[i]-'0') * pw[s.size()-i-1];
		}
		x++;
	}
		//cerr << (int)x << endl;

	if(x == 1){
		cout << bv[0] << endl;
		return;
	}

	s = "";
	if(b[0]){
		x--;
		while(x){
			s.push_back((x % bc) + '0');
			x /= bc;
		}
		reverse(s.begin(), s.end());
	}else{
		i128 pp = bc, len = 1;
		while(x > pp){
			len++;
			x -= pp;
			pp *= bc;
		}
		//cerr << (int)x << endl;
		vector<i128>pw(len);
		pw[0] = 1;
		for(int i = 1;i < len;i++) pw[i] = pw[i-1] * bc;
		s = string(len, '0');
		for(int i = 0;i < len;i++){
			//cerr << (int)x << ' ' << (int)pw[len-i-1] << endl;
			if(x > pw[len-i-1]) {
				s[i] += (x-1) / pw[len-i-1];
				x -= pw[len-i-1] * (s[i]-'0');
			}
		}
		//cerr << s << endl;
	}

	for(auto &c : s) {
		c = bv[c-'0'] + '0';
	}
	cout << s << endl;
}

signed main(){

	ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
	int t = 1;
	cin >> t;
	while(t--) solve();

	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 15ms
memory: 3584kb

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