QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#707382#6562. First Lastucup-team902#RE 0ms0kbC++171.4kb2024-11-03 15:45:322024-11-03 15:45:33

Judging History

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

  • [2024-11-03 15:45:33]
  • 评测
  • 测评结果:RE
  • 用时:0ms
  • 内存:0kb
  • [2024-11-03 15:45:32]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
#define cs const
#define re register
#define pb push_back
#define pii pair<int,int>
#define ll long long
#define fi first
#define se second
#define bg begin
#define gc getchar
inline int read(){
	char ch=gc();
	int res=0;bool f=1;
	while(!isdigit(ch))f^=ch=='-',ch=gc();
	while(isdigit(ch))res=(res+(res<<2)<<1)+(ch^48),ch=gc();
	return f?res:-res;
}
template<typename tp>inline void chemx(tp &a,tp b){(a<b)?(a=b):0;}
template<typename tp>inline void chemn(tp &a,tp b){(a>b)?(a=b):0;}


int id[30],m,n;
int cnt[3][3];
int now[3][3];
bool dfs(int x){
	int ok=1;
	for(int i=0;i<3;i++)if(now[x][i]){
		now[x][i]--;
		ok&=dfs(i);
		now[x][i]++;
	}
	return ok^1;
}
int main(){
	#ifdef Stargazer
	freopen("1.in","r",stdin);
	#endif
	cin>>n;
	for(int i=1;i<=n;i++){
		string s;cin>>s;int l=s.length();
		int xx=s[0]-'a',yy=s[l-1]-'a';
		if(!id[xx])id[xx]=m++;
		if(!id[yy])id[yy]=m++;
		cnt[xx][yy]++;
	}
	assert(m<=3);
	int ans=0;
	for(int x=0;x<3;x++)
	for(int y=0;y<3;y++)if(cnt[x][y]){
		memcpy(now,cnt,sizeof(cnt));
		now[x][y]--;
		for(int i=0;i<3;i++)now[i][i]&=1;
		for(int i=0;i<3;i++)
		for(int j=0;j<3;j++)if(i!=j){
			int t=min(now[i][j],now[j][i]);
			now[i][j]-=t,now[j][i]-=t;
		}
		vector<int> sta;
		for(int i=0;i<3;i++)
		for(int j=0;j<3;j++)
		if(!dfs(y))ans+=cnt[x][y];
	}
	cout<<ans<<'\n';
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Runtime Error

input:

3
attic
climb
alpha

output:


result: