QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#624618 | #9107. Zayin and Count | expectant# | AC ✓ | 15ms | 5672kb | C++14 | 1.4kb | 2024-10-09 16:15:29 | 2024-10-09 16:15:29 |
Judging History
answer
#include <bits/stdc++.h>
#define rep(i,j,k) for(int i=j;i<=(k);++i)
#define drp(i,j,k) for(int i=j;i>=(k);--i)
#define MAXN 1000005
typedef long long ll;
typedef __int128 i128;
inline int read(){
int x=0;
bool sgn=true;
char ch=getchar();
while(!isdigit(ch)) sgn^=ch=='-',ch=getchar();
while(isdigit(ch)) x=(x<<3)+(x<<1)+(ch^48),ch=getchar();
return sgn?x:-x;
}
inline void chkmin(int &x,int y){x=std::min(x,y);}
int a[MAXN],b[MAXN];
std::string s;
std::vector<int> v1,v2;
inline void init(){
std::vector<int>().swap(v1);
std::vector<int>().swap(v2);
}
inline int chk(int x){
if(!x) return 0;
return a[0]==0?1:0;
}
inline void solve(){
i128 cur=1,x=0;
std::string ans;
rep(i,0,(int)s.length()-1){
int pos=std::lower_bound(v1.begin(),v1.end(),s[i]-'0')-v1.begin();
x+=(pos+chk(i))*cur,cur*=v1.size();
}
if(b[0]){
if(!x) ans+=v2[0]+'0';
else while(x){
int pos=x%v2.size();
ans+=v2[pos]+'0',x/=v2.size();
}
}
else{
int len=1;
i128 tmp=v2.size();
while(tmp<=x) ++len,x-=tmp,tmp*=v2.size();
while(len--){
int pos=x%v2.size();
ans+=v2[pos]+'0',x/=v2.size();
}
}
std::reverse(ans.begin(),ans.end());
std::cout<<ans<<'\n';
}
int main(){
drp(task,read(),1){
init();
rep(i,0,9) a[i]=read();
rep(i,0,9) b[i]=read();
std::cin>>s,std::reverse(s.begin(),s.end());
rep(i,0,9) if(a[i]) v1.push_back(i);
rep(i,0,9) if(b[i]) v2.push_back(i);
solve();
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 15ms
memory: 5672kb
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