QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#153233#6562. First Lastqzez#WA 2ms3620kbC++143.5kb2023-08-29 18:35:352023-08-29 18:35:36

Judging History

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

  • [2023-08-29 18:35:36]
  • 评测
  • 测评结果:WA
  • 用时:2ms
  • 内存:3620kb
  • [2023-08-29 18:35:35]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
using ll=long long;
template<typename T>
ostream& operator << (ostream &out,const vector<T>&x){
	if(x.empty())return out<<"[]";
	out<<'['<<x[0];
	for(int len=x.size(),i=1;i<len;i++)out<<','<<x[i];
	return out<<']';
}
template<typename T>
vector<T> ary(const T *a,int l,int r){
	return vector<T>{a+l,a+1+r};
}
template<typename T>
void debug(T x){
	cerr<<x<<'\n';
}
template<typename T,typename ...S>
void debug(T x,S ...y){
	cerr<<x<<' ',debug(y...);
}
map<vector<int>,int>s;
void sub(int &x,int &y){
	int t=min(x,y);
	x-=t,y-=t;
}
int dfs(int aa,int bb,int cc,int ac,int bc,int ab,int ba,int cb,int ca,int x=0){
	aa%=2,bb%=2,cc%=2;
	sub(ac,ca),sub(ab,ba),sub(bc,cb);
	if(x==1){
		swap(aa,bb),swap(ac,bc),swap(ab,ba),swap(cb,ca);
	}else if(x==2){
		swap(aa,cc),swap(ac,ca),swap(bc,ba),swap(cb,ab);
	}
	vector<int> hsh{aa,bb,cc,ac,bc,ab,ba,cb,ca};
	if(s.count(hsh))return s[hsh];
	if(aa&&!dfs(aa-1,bb,cc,ac,bc,ab,ba,cb,ca))return s[hsh]=1;
	if(ab&&!dfs(aa,bb,cc,ac,bc,ab-1,ba,cb,ca,1))return s[hsh]=1;
	if(ac&&!dfs(aa,bb,cc,ac-1,bc,ab,ba,cb,ca,2))return s[hsh]=1;
	return s[hsh]=0;
}
int main(){
	int n=3;
	// for(int aa=0;aa<=n;aa++){
	// 	for(int bb=0;bb<=n;bb++){
	// 		for(int cc=0;cc<=n;cc++){
	// 			for(int ac=0;ac<=n;ac++){
	// 				for(int bc=0;bc<=n;bc++){
	// 					for(int ab=0;ab<=n;ab++){
	// 						for(int ba=0;ba<=n;ba++){
	// 							for(int cb=0;cb<=n;cb++){
	// 								for(int ca=0;ca<=n;ca++){
	// 									// if(!)
	// 									// debug(aa,bb,cc,ac,bc,ab,ba,cb,ca,"ans=",dfs(aa,bb,cc,ac,bc,ab,ba,cb,ca));
	// 									assert(
	// 										dfs(aa,bb,cc,ac,bc,ab,ba,cb,ca)
	// 										==
	// 										dfs(aa%2,bb%2,cc%2,
	// 											ac-min(ac,ca),bc-min(bc,cb),ab-min(ab,ba),
	// 											ba-min(ab,ba),cb-min(bc,cb),ca-min(ac,ca))
	// 									);
	// 									assert(
	// 										dfs(aa,bb,cc,ac,bc,ab,ba,cb,ca)
	// 										==
	// 										dfs(aa,bb,cc,ac,bc,ab,ba,cb,ca)
	// 									);
	// 								}
	// 							}
	// 						}
	// 					}
	// 				}
	// 			}
	// 		}
	// 	}
	// }
	int aa=0,bb=0,cc=0,ab=0,ba=0,ac=0,ca=0,bc=0,cb=0;
	// for(int aa=0;aa<=1;aa++){
	// 	for(int bb=0;bb<=1;bb++){
	// 		for(int cc=0;cc<=1;cc++){
	// 			for(int bc=1;bc<=n;bc++){
	// 				for(int ab=1;ab<=n;ab++){
	// 					for(int ca=1;ca<=n;ca++){
	// 						// if(!)
	// 						debug(aa,bb,cc,ab,bc,ca,"ans",dfs(aa,bb,cc,ac,bc,ab,ba,cb,ca));
	// 						// assert(
	// 						// 	dfs(aa,bb,cc,ac,bc,ab,ba,cb,ca)
	// 						// 	==
	// 						// 	dfs(aa,bb,cc,ac,bc,ab,ba,cb,ca)
	// 						// );
	// 					}
	// 				}
	// 			}
	// 		}
	// 	}
	// }
	cin>>n;
	for(string s;n--;){
		cin>>s;
		if(s[0]=='a'){
			if(s.back()=='a')aa++;
			else if(s.back()=='b')ab++;
			else ac++;
		}else if(s[0]=='b'){
			if(s.back()=='a')ba++;
			else if(s.back()=='b')bb++;
			else bc++;
		}else{
			if(s.back()=='a')ca++;
			else if(s.back()=='b')cb++;
			else cc++;
		}
	}
	int ans=0;
	if(aa)ans+=!dfs(aa-1,bb,cc,ac,bc,ab,ba,cb,ca)*aa;
	if(bb)ans+=!dfs(aa,bb-1,cc,ac,bc,ab,ba,cb,ca,1)*bb;
	if(cc)ans+=!dfs(aa,bb,cc-1,ac,bc,ab,ba,cb,ca,2)*cc;
	if(ab)ans+=!dfs(aa,bb,cc,ac,bc,ab-1,ba,cb,ca,1)*ab;
	if(ba)ans+=!dfs(aa,bb,cc,ac,bc,ab,ba-1,cb,ca)*ba;
	if(ac)ans+=!dfs(aa,bb,cc,ac-1,bc,ab,ba,cb,ca,2)*ac;
	if(ca)ans+=!dfs(aa,bb,cc,ac,bc,ab,ba,cb,ca-1)*ca;
	if(bc)ans+=!dfs(aa,bb,cc,ac,bc-1,ab,ba,cb,ca,2)*bc;
	if(cb)ans+=!dfs(aa,bb,cc,ac,bc,ab,ba,cb-1,ca,1)*cb;
	cout<<ans<<endl;
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3620kb

input:

3
attic
climb
alpha

output:

2

result:

ok single line: '2'

Test #2:

score: 0
Accepted
time: 2ms
memory: 3556kb

input:

22
agora
alpha
antic
aorta
apnea
arena
aroma
attic
basic
blurb
china
circa
civic
climb
cobra
cocoa
comic
comma
conic
crumb
cubic
cynic

output:

6

result:

ok single line: '6'

Test #3:

score: 0
Accepted
time: 2ms
memory: 3616kb

input:

3
ccabaabbba
acbbbacccb
ccccccacba

output:

1

result:

ok single line: '1'

Test #4:

score: -100
Wrong Answer
time: 2ms
memory: 3616kb

input:

11
mraa
myga
vtwm
mala
vvgm
atvv
vusm
mznv
avea
atfv
amgv

output:

4

result:

wrong answer 1st lines differ - expected: '7', found: '4'