QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#471556 | #9107. Zayin and Count | real_sigma_team# | AC ✓ | 13ms | 3544kb | C++23 | 1.8kb | 2024-07-10 22:03:18 | 2024-07-10 22:03:18 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#ifdef lisie_bimbi
#else
#define endl '\n'
#endif
typedef __int128 ll;
void solve(){
vector<int> a(10), b(10);
for(ll i = 0; i < 10; i++){
cin >> a[i];
}
for(ll i = 0; i < 10; i++){
cin >> b[i];
}
for(ll i = 1; i < 10; i++){
a[i] += a[i - 1];
}
string s;
cin >> s;
ll n = s.size();
ll x = 0;
ll c = 1;
reverse(s.begin(), s.end());
for(int i = 0; i < n; i++){
x += c * (a[s[i] - '0'] - 1);
if(!a[0]){
x += c;
}
c *= a[9];
//cout << (long long)x << " " << (long long)c << endl;
}
if(!a[0]){
x--;
}
//cout << (long long)x << endl;
vector<ll> b1;
for(ll i = 0; i < 10; i++){
if(b[i]){
b1.push_back(i);
}
}
string ans;
ll sz = b1.size();
if(b[0]){
while(x > 0){
ans += ('0' + b1[x % sz]);
x /= sz;
}
reverse(ans.begin(), ans.end());
if(ans.empty()){
ans += '0';
}
cout << ans << endl;
}else{
x++;
ll s = 1;
int cnt = 0;
while(s < x){
x -= s;
s *= sz;
cnt++;
}
while(cnt--){
ans += ('0' + b1[x % sz]);
x /= sz;
}
reverse(ans.begin(), ans.end());
if(ans.empty()){
ans += '0';
}
cout << ans << endl;
}
}
signed main(){
#ifdef lisie_bimbi
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#else
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
#endif
int t;
cin >> t;
while(t--){
solve();
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 13ms
memory: 3544kb
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