QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#619342#9107. Zayin and CounttreasuresgcAC ✓30ms3552kbC++231.4kb2024-10-07 13:55:302024-10-07 13:55:35

Judging History

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

  • [2024-10-07 13:55:35]
  • 评测
  • 测评结果:AC
  • 用时:30ms
  • 内存:3552kb
  • [2024-10-07 13:55:30]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
#define i128 __int128
#define int long long
void solve(){
	vector<int>a, b;
	vector<int> ta(11), tb(11);
	for(int i = 0; i <= 9; ++ i){
		int x; cin >> x;
		if(x == 0) ta[i] = -1;
		else {
			ta[i] = a.size();
			a.push_back(i);
		}
	}
	for(int i = 0; i <= 9; ++ i){
		int x; cin >> x;
		if(x == 0) tb[i] = -1;
		else {
			tb[i] = b.size();
			b.push_back(i);
		}
	}
	string str; cin >> str;
	i128 ss = 0, ka = a.size(), kb = b.size();
	if(a[0] == 0){
		int p = 1;
		for(int i = str.size() - 1; i >= 0; -- i){
			char ch = str[i]; 
			ss += p * ta[(ch - '0')];
			p = p * ka;
		} 
	}else{
		i128 p = ka;
		for(int i = 1; i <= str.size() - 1; ++ i){
			ss += p;
			p = p * ka;
		}
		p = 1;
		for(int i = str.size() - 1; i >= 0; -- i){
			char ch = str[i];
			ss += p * ta[(ch - '0')];
			p = p * ka;
		}
	}
//	cout << (int)ka << endl;
//	cout << (int)ss << endl;
	vector<int>ans;
	if(b[0] == 0){
		i128 p = 1;
		while(ss){
			ans.push_back(b[ss % kb]);
			ss = ss / kb;
		}
	}else{
		int siz = 1;
		i128 p = kb, tt = kb;
		while(p <= ss){
			ss -= p;
			p = p * kb;
			siz ++;
		}
		for(int i = 1; i <= siz; ++ i){
			ans.push_back(b[ss % kb]);
			ss = ss / kb;	
		}
	}
	for(int i = ans.size() - 1; i >= 0; -- i){
		cout << ans[i];
	}
	cout << endl;
}
signed main(){
	ios::sync_with_stdio(0);
	int T;
	cin >> T;
	while(T--) solve();
}

詳細信息

Test #1:

score: 100
Accepted
time: 30ms
memory: 3552kb

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