QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#707382 | #6562. First Last | ucup-team902# | RE | 0ms | 0kb | C++17 | 1.4kb | 2024-11-03 15:45:32 | 2024-11-03 15:45:33 |
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