QOJ.ac
QOJ
The 2nd Universal Cup Finals is coming! Check out our event page, schedule, and competition rules!
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#175630 | #6562. First Last | SolitaryDream# | RE | 2ms | 3856kb | C++17 | 1.5kb | 2023-09-10 20:51:45 | 2023-09-10 20:51:46 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
const int N=1e3+1e2+7;
int n;
string s[N];
map<vector<vector<int> >, int>dp[3];
int m;
int dfs(vector<vector<int> >g,int p)
{
if(dp[p].count(g))
return dp[p][g];
auto &ret=dp[p][g];
ret=0;
for(int i=0;i<m;i++)
if(g[p][i])
{
auto ng=g;
ng[p][i]--;
ret|=!dfs(ng,i);
}
return ret;
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
cin>>n;
vector<char> X;
for(int i=1;i<=n;i++)
cin>>s[i],X.push_back(*s[i].begin()),X.push_back(s[i].back());
sort(X.begin(),X.end());
X.erase(unique(X.begin(),X.end()),X.end());
m=X.size();
vector<vector<int> >g(m,vector<int>(m));
for(int i=1;i<=n;i++)
{
int u=lower_bound(X.begin(),X.end(),*s[i].begin())-X.begin();
int v=lower_bound(X.begin(),X.end(),s[i].back())-X.begin();
g[u][v]++;
}
int ans=0;
for(int i=0;i<m;i++)
for(int j=0;j<m;j++)
{
auto tg=g;
if(!tg[i][j])
continue;
tg[i][j]--;
for(int a=0;a<3;a++)
{
tg[a][a]%=2;
for(int b=a+1;b<3;b++)
{
int t=min(tg[a][b],tg[b][a]);
tg[a][b]-=t;
tg[b][a]-=t;
}
}
if(!dfs(tg,j))
ans+=g[i][j];
}
printf("%d\n",ans);
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 2ms
memory: 3664kb
input:
3 attic climb alpha
output:
2
result:
ok single line: '2'
Test #2:
score: 0
Accepted
time: 0ms
memory: 3660kb
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: 1ms
memory: 3856kb
input:
3 ccabaabbba acbbbacccb ccccccacba
output:
1
result:
ok single line: '1'
Test #4:
score: 0
Accepted
time: 1ms
memory: 3784kb
input:
11 mraa myga vtwm mala vvgm atvv vusm mznv avea atfv amgv
output:
7
result:
ok single line: '7'
Test #5:
score: -100
Runtime Error
input:
1000 vznwivhoprv pvzcjyruxv phykv vozinczup vbp vgjxfotuhzhobfp pbv vygphslv vpnqrfep vzrphpfggoqcgv vgdjmzuckyedpnp vatmaxfp ppnmmwtqmv paawwp pspoycv vcjthv ppcvagp pteiqdonkklp vav vcsxv priqwbalidav vinp phqeijnqkgbxv pwvmbivmgvouv vwzhndzmqpcwkmp pyzlv vtvblfov vrdv vzrfmjdnaruwp pfup pwzv vwyv...