QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#102395#6172. 加法方程问题sszcdjr90 248ms4200kbC++203.8kb2023-05-03 12:39:362023-05-03 12:39:40

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-05-03 12:39:40]
  • 评测
  • 测评结果:90
  • 用时:248ms
  • 内存:4200kb
  • [2023-05-03 12:39:36]
  • 提交

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;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 10
Accepted
time: 12ms
memory: 4076kb

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: 4124kb

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: 6ms
memory: 3516kb

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: 159ms
memory: 3588kb

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: 216ms
memory: 4116kb

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: 203ms
memory: 4092kb

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: 238ms
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: 214ms
memory: 3516kb

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: 248ms
memory: 4116kb

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