QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#102387 | #6172. 加法方程问题 | sszcdjr | 90 | 252ms | 4200kb | C++14 | 3.8kb | 2023-05-03 12:29:18 | 2023-05-03 12:29:20 |
Judging History
answer
#include <bits/stdc++.h>
#pragma GCC optimize(3)
#pragma GCC target("avx")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("inline")
#pragma GCC optimize("-fgcse")
#pragma GCC optimize("-fgcse-lm")
#pragma GCC optimize("-fipa-sra")
#pragma GCC optimize("-ftree-pre")
#pragma GCC optimize("-ftree-vrp")
#pragma GCC optimize("-fpeephole2")
#pragma GCC optimize("-ffast-math")
#pragma GCC optimize("-fsched-spec")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("-falign-jumps")
#pragma GCC optimize("-falign-loops")
#pragma GCC optimize("-falign-labels")
#pragma GCC optimize("-fdevirtualize")
#pragma GCC optimize("-fcaller-saves")
#pragma GCC optimize("-fcrossjumping")
#pragma GCC optimize("-fthread-jumps")
#pragma GCC optimize("-funroll-loops")
#pragma GCC optimize("-fwhole-program")
#pragma GCC optimize("-freorder-blocks")
#pragma GCC optimize("-fschedule-insns")
#pragma GCC optimize("inline-functions")
#pragma GCC optimize("-ftree-tail-merge")
#pragma GCC optimize("-fschedule-insns2")
#pragma GCC optimize("-fstrict-aliasing")
#pragma GCC optimize("-fstrict-overflow")
#pragma GCC optimize("-falign-functions")
#pragma GCC optimize("-fcse-skip-blocks")
#pragma GCC optimize("-fcse-follow-jumps")
#pragma GCC optimize("-fsched-interblock")
#pragma GCC optimize("-fpartial-inlining")
#pragma GCC optimize("no-stack-protector")
#pragma GCC optimize("-freorder-functions")
#pragma GCC optimize("-findirect-inlining")
#pragma GCC optimize("-fhoist-adjacent-loads")
#pragma GCC optimize("-frerun-cse-after-loop")
#pragma GCC optimize("inline-small-functions")
#pragma GCC optimize("-finline-small-functions")
#pragma GCC optimize("-ftree-switch-conversion")
#pragma GCC optimize("-foptimize-sibling-calls")
#pragma GCC optimize("-fexpensive-optimizations")
#pragma GCC optimize("-funsafe-loop-optimizations")
#pragma GCC optimize("inline-functions-called-once")
#pragma GCC optimize("-fdelete-null-pointer-checks")
#pragma GCC optimize(2)
#define int long long
#define double long double
using namespace std;
char reg[15];
int num[150],tot;
int ci[15],usd[15];
int a[17],b[17],n=0,m=0,c[17];
vector<int> vc;
void dfs(int lev){
if(lev==tot+1){
if(ci[a[n]]==0) return ;
if(ci[b[m]]==0) return ;
int tot1=0,tot2=0;
// for(int i=1;i<=tot;i++) cout<<ci[i]<<" ";
for(int i=0;i<=16;i++) c[i]=0;
for(int i=1;i<=max(n,m);i++){
if(n>=i) c[i]+=ci[a[i]];
if(m>=i) c[i]+=ci[b[i]];
if(c[i]>=10) c[i+1]++,c[i]-=10;
}
int k=max(n,m); if(c[k+1]!=0) k++;
int ntt=tot;
int ts=0;
for(int i=k;i>=1;i--){
// cout<<c[i]<<" ";
if(usd[c[i]]==-1) usd[c[i]]=++ntt;
ts=ts*13+usd[c[i]];
}
// cout<<ts<<endl;
for(int i=k;i>=1;i--) if(usd[c[i]]>tot) usd[c[i]]=-1;
vc.push_back(ts);
return ;
}
for(int i=0;i<=9;i++){
if(usd[i]==-1){
usd[i]=lev;
ci[lev]=i;
dfs(lev+1);
usd[i]=-1;
}
}
}
signed main(){
memset(usd,-1,sizeof(usd));
memset(num,-1,sizeof(num));
tot=-1;
string s1,s2; cin>>s1>>s2;
for(int i=s1.size()-1;i>=0;i--){
if(num[s1[i]]==-1) num[s1[i]]=++tot,reg[tot]=s1[i];
a[++n]=num[s1[i]];
// cout<<a[n]<<" ";
}
// cout<<endl;
for(int i=s2.size()-1;i>=0;i--){
if(num[s2[i]]==-1) num[s2[i]]=++tot,reg[tot]=s2[i];
b[++m]=num[s2[i]];
// cout<<b[m]<<" ";
}
// cout<<endl;
dfs(0);
sort(vc.begin(),vc.end());
int N,M,K; cin>>N>>M>>K;
while(N--){
string s; cin>>s;
int sz=s.size();
int ntt=tot;
int ts=0;
for(int i=0;i<sz;i++){
if(num[s[i]]==-1) num[s[i]]=++ntt;
ts=ts*13+num[s[i]];
}
for(int i=0;i<sz;i++) if(num[s[i]]>tot) num[s[i]]=-1;
if(ntt>9){
cout<<"NO\n";
continue;
}
// cout<<ans[ts]<<" "<<ts<<" ";
int dd=lower_bound(vc.begin(),vc.end(),ts)-vc.begin(),uu=upper_bound(vc.begin(),vc.end(),ts)-vc.begin();
int ans=uu-dd;
if(ans%M==K) cout<<"YES\n";
else cout<<"NO\n";
}
return 0;
}
详细
Test #1:
score: 10
Accepted
time: 16ms
memory: 4080kb
input:
eadefcfeb fbbbbaef 100 3628801 1 eywwzxycz wycxzzycz ywwaxwxyz exxzdyczz zwycwxzyz fcydddyza xyyyzfyfz xyfefzbfa eywddxyzd ycxacyczc bzbxwxzyz ecyzxfyfz aefzcdefc vwxydbyzz eyayzzyaz exzvzwxyz eyabaayez zevxwbxyz exxvcwxyz ydfaeaaaz ecyfzdcfz xydefccyz eyyyzxyyz aywvwxyyz yzywbyxyez eyybxxyez xyezdf...
output:
NO NO NO NO NO NO NO NO NO NO NO NO YES NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO YES NO NO NO YES NO NO YES NO YES NO NO NO NO NO YES NO NO NO NO NO NO NO YES NO NO NO NO NO NO NO NO NO NO YES NO NO YES NO NO NO NO NO YES NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO...
result:
ok 100 token(s): yes count is 10, no count is 90
Test #2:
score: 10
Accepted
time: 21ms
memory: 4104kb
input:
eaaafeecfb ffdeace 100 3628801 1 eafxxyzbba eaacydzedc eaaeyezzzc eazcycfezc fayafdfafz eafvawxyyz wxxfyyzdzf byyfyazcbz effdxfyddz eafaazyeez eccdxyfezc eaawexxyza wzzfxxycdz eccecxxyez xyyyffdfccz eaazxcyafz ebdzwdexyz eafxzycyez eaeyeayzaz eaaxzbfybz axxcayzdec efdccwxdyz eexczzcyyz yzzcyfazef eb...
output:
YES YES NO NO NO NO NO YES NO NO NO NO NO NO NO NO NO YES NO YES YES NO NO NO NO YES NO YES NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO YES NO NO YES NO NO NO NO YES NO NO NO NO NO NO YES NO YES NO NO NO NO NO YES NO YES NO NO NO YES NO NO YES NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO N...
result:
ok 100 token(s): yes count is 17, no count is 83
Test #3:
score: 10
Accepted
time: 7ms
memory: 3520kb
input:
bbddeadffd ebbaafafaa 100 3628801 1 dxydefzzfz faaawzyzxyz zvyfwyywxyz zexwdvwxyz zxazwdxydz wxeyyxeyeez zewyxzybzz dzbafyzdyz ybxbaayazyz wvezfywxyz xddzyxyzbyz uvxwyywxyz dywzxyzdyz yyafyaayfaz xfyzbyyayz yebzbzebeeb zwffzxzyezz yxezfeeyez yebffeffefz yfezyzxyzz yezzyezeez ddxyzdyzde wxfxbyabfaz w...
output:
NO NO NO NO NO NO YES YES NO NO NO NO YES NO YES NO NO NO NO NO NO NO YES NO NO NO YES YES NO NO NO NO NO NO NO NO NO NO YES NO NO NO YES NO YES NO NO NO YES NO YES NO NO YES NO NO NO NO NO NO NO YES NO NO YES NO NO NO NO NO NO NO NO YES NO NO NO YES NO YES NO NO YES YES NO NO NO YES NO NO NO YES YE...
result:
ok 100 token(s): yes count is 25, no count is 75
Test #4:
score: 10
Accepted
time: 189ms
memory: 3532kb
input:
ecaecccaf cbbfcbccec 80000 17 2 tuvwyxzzyz ftuvwxxyfz cstuuvwxyz rstuvxwxyz btuvvwxyyz tuuywvwxyz csvtuvwxyz fstuvwxxyz uqrstuvwxyz rstuvwexyz stuvzevwxyz uxxvwxzzyz tuvevwxfyz awstuvwxyz sttuwvwxyz qrstuvwxyz tuvwbzxyza stvuavwxyz rstyuvwxyz aazyzvwxyz uvwxffxycfz stuvwxybfz qrstuvwxyz rsatuvwxyz r...
output:
NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO ...
result:
ok 80000 token(s): yes count is 8, no count is 79992
Test #5:
score: 10
Accepted
time: 211ms
memory: 4136kb
input:
fdebefeac affdaadafbaabc 80000 1000 1 affdfyydfeadyz afffydbezffebz affdxzcafeyaaz effdeydffcyfcz effeewzxvywxyz affdazzzddzxyz bffebxyfxfxfyz effdfxwyecxyzd dffdbwbvdzwxyz affdaccdyaedza cffdwyxcycyzff affdvbzvwxbyez affdfxyyzcbyzz afffwyxfebyazb affzxzycazfeff affdcdxdzzddyz dffdwybfxyyfzf ffffzxx...
output:
NO NO NO NO NO NO NO NO NO YES NO NO YES NO NO NO NO NO NO NO NO NO YES NO NO NO NO NO NO YES NO NO NO NO NO YES NO NO NO NO NO NO NO NO NO NO NO YES NO NO NO NO YES NO YES NO NO NO YES NO NO NO NO NO NO NO NO YES NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO YES NO YES NO NO NO NO YES NO NO...
result:
ok 80000 token(s): yes count is 9332, no count is 70668
Test #6:
score: 10
Accepted
time: 247ms
memory: 4128kb
input:
dbaabddec fabffbb 80000 1000 2 dwxwdxyze dbxyebbze zyyeazcez dczzzexyz evfxwxxyz defdyaazd efeyceeze dfzwxzzyz dzxfdzzyz dbvwxbyzd dfwyyxxyz dzywaxxyz eyzwzxxyz ddyxxyeze eeyxfyycz dbxyzzzfd dfwfdxzyz dfdfxfeyz dzbyydzzd dwyfcxxyz dwxdfdyfz ewfxyzzff ebbewxxyz dbybczecf dbxeeceyz dfexxddyz dwxfzyzcd...
output:
NO NO NO NO NO YES NO NO NO NO NO NO NO NO NO YES NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO YES NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO YES NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO...
result:
ok 80000 token(s): yes count is 3435, no count is 76565
Test #7:
score: 10
Accepted
time: 231ms
memory: 4200kb
input:
abbebbbccded ddcacbafebbcac 80000 500 15 dwfxfyxxyffdyz dcdaceafeccxyz ddzxdyxdddyzzz ffwyfyfxyffzcz fwxzvfzwwxxzyz dddcwxcczyyzyz ffyzewxyyffzce efccfxvxxwfxyz ezvzvwzcyxxbyz dddcfdcdwfxcyz ddzxzzxyzzdfdf dxfefzeyzaafcf ffbzabzcbaayaz ddvwwdwddwxzyz dddzzyzxyzzzfz ffeaceafecccyz eebwfwzzxefzyz dbew...
output:
NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO ...
result:
ok 80000 token(s): yes count is 25, no count is 79975
Test #8:
score: 10
Accepted
time: 194ms
memory: 3512kb
input:
bfcfeeefb beeea 100000 778 23 wfxeeffyz effzeeefz bfccyffbz bfyyzycbz cwccwxxyz bfffzxfyz tuvwaaxyz bfcxbyyzf bycfacczz czcaexxyz wfcfycxyz bfefvwxyz bwcwfxyzf bfzvwxybz bfvzwxxyz efexaaxyz bwcbwxxyz yfccwxxyz bvcvwxxyz xfcfyzzaz cfcexyyze ffefxfyzz yfcwzfxyz bxxwxyyyz bffwaxyzz bfexxzzyz bfefwbxyz ...
output:
NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO YES NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO YES NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO N...
result:
ok 100000 token(s): yes count is 785, no count is 99215
Test #9:
score: 0
Time Limit Exceeded
input:
bcddefbdadfee dcdcb 100000 997 35 uuddfffdvwxyz ycddufvwxcxyz bcweefbxyyeyz vyddefewxzyfz veuuefvzwxyzz xexxefxayfazf bvvdefbwyxyfz feddeffdyxyez wcddefwdxyzbz vvwwefcfcxyzz bwddwfbdbxxyz wcudevwxyecyz bwddxfbyfzaff dcddffddxaxyz bxeeefbyzfbfa bcddefbdbzcez fcffefffvwxyz wvddefwdxycyz fcddeffdewxyz ...
output:
NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO ...
result:
Test #10:
score: 10
Accepted
time: 252ms
memory: 4124kb
input:
edebbcdfff defca 100000 993 44 edebxdyyfz edebezazbd vdvwwwxyzc vdvbwxbybz edeyacebzd eeecxwxxyz ezefewxzyz xdvwwdxyfz edebbabyzd wfeffyxeyz vdvbycwxyz ezewyzxxyz edewwexzyz vvfwxbycbz edebcbdyzz efebyzcbfz wdweexyczc vwvbwxyzae eeezyxwxyz zfzffyxyaz edexbyzzzc ewewfxyyzz ededxydaze edecdwxyaz vuvbc...
output:
NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO ...
result:
ok 100000 token(s): yes count is 18, no count is 99982