QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#412808 | #6562. First Last | grass8cow# | AC ✓ | 0ms | 3964kb | C++17 | 1.1kb | 2024-05-16 19:44:42 | 2024-05-16 19:44:42 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
int n,ct[3][3],ce[3][3];
char c[1010];
int rk[1010],m;
#define vi array<int,10>
map<vi,bool>oz;
bool dfs(vi a){
if(oz.find(a)!=oz.end())return oz[a];
int p=a[9];
for(int i=0;i<3;i++)if(a[p*3+i]){
vi b=a;
b[p*3+i]--,b[9]=i;
if(!dfs(b))return oz[a]=1;
}
return oz[a]=0;
}
int main(){
scanf("%d",&n);
for(int i=1;i<=n;i++){
scanf("%s",c);int L=strlen(c),x=c[0]-'a',y=c[L-1]-'a';
if(!rk[x])rk[x]=++m;if(!rk[y])rk[y]=++m;
x=rk[x]-1,y=rk[y]-1;
ct[x][y]++;
}
int ans=0;
for(int si=0;si<3;si++)for(int sj=0;sj<3;sj++)if(ct[si][sj]){
for(int i=0;i<3;i++)for(int j=0;j<3;j++)ce[i][j]=ct[i][j];
ce[si][sj]--;
for(int i=0;i<3;i++)ce[i][i]&=1;
for(int i=0;i<3;i++)for(int j=i+1;j<3;j++){
int e=min(ce[i][j],ce[j][i]);
ce[i][j]-=e,ce[j][i]-=e;
}
vi s;
for(int i=0;i<3;i++)for(int j=0;j<3;j++)s[i*3+j]=ce[i][j];
s[9]=sj;
if(!dfs(s))ans+=ct[si][sj];
}
printf("%d\n",ans);
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3872kb
input:
3 attic climb alpha
output:
2
result:
ok single line: '2'
Test #2:
score: 0
Accepted
time: 0ms
memory: 3876kb
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: 0ms
memory: 3760kb
input:
3 ccabaabbba acbbbacccb ccccccacba
output:
1
result:
ok single line: '1'
Test #4:
score: 0
Accepted
time: 0ms
memory: 3812kb
input:
11 mraa myga vtwm mala vvgm atvv vusm mznv avea atfv amgv
output:
7
result:
ok single line: '7'
Test #5:
score: 0
Accepted
time: 0ms
memory: 3800kb
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...
output:
478
result:
ok single line: '478'
Test #6:
score: 0
Accepted
time: 0ms
memory: 3884kb
input:
1000 rlp pgscawiivpjndlp pxr ruzutr pqdhfniemqvvr rvar rp prarwp pkuinxempbmear rupxuanwlvawmr pp rzfvr rcsxoyirp pgpilljr pogeizvqlr rajolbgzswur rcap ryzqymwr rrpp rbxtr rfldblbesyhqr rjidcekyrir pqrycftr rftwgmmakykkmep pehkxkayuip pguxsgtuikvp rtxmynvoolrp pzmsljlpcr phcfdr plaop rydojaccp pzfr ...
output:
246
result:
ok single line: '246'
Test #7:
score: 0
Accepted
time: 0ms
memory: 3872kb
input:
1000 ffn fgikjn fwtakdbjn fsjnfzzn feqmuasubirsf faypin fcsdhfjvncfzsn nbcmvxemkan ngoqtaaon nlovkxxrbn fhdqkltoxvif fxpnqbguftsrhff fyniukvsmlf fibwbqckjpojglf nwcvf fxgeivnakggcn nn fkghlusecf neuwdafrkzptwf fcxn ff nlkxtn fdlsijtpbcjjcbn frlcjjnpsn ntyabhf nvf fdlmlhebidazhn fjn fstxgnmfof fqhusf...
output:
496
result:
ok single line: '496'
Test #8:
score: 0
Accepted
time: 0ms
memory: 3956kb
input:
15 adb bdc cda aeb bec cea afb bfc cfa agb bgc cga ahb bhc cha
output:
15
result:
ok single line: '15'
Test #9:
score: 0
Accepted
time: 0ms
memory: 3864kb
input:
1 alpha
output:
1
result:
ok single line: '1'
Test #10:
score: 0
Accepted
time: 0ms
memory: 3796kb
input:
3 alpha beta gamma
output:
1
result:
ok single line: '1'
Test #11:
score: 0
Accepted
time: 0ms
memory: 3832kb
input:
2 alpha beta
output:
1
result:
ok single line: '1'
Test #12:
score: 0
Accepted
time: 0ms
memory: 3780kb
input:
20 ccbccaabaa aaccbbbbab bcbcbccabc bbbabcbbcc ccaaccabca acabbbccab baacbcbccc bcbbabbbbc bccbbbbabc bacaccbcac cbbabbbaca ccaaacbaaa acbbbaccab bcaacaaacc aabbaabcbb bbbabbbbcc aabcaaabcb aabbbaaacb acacaababb abacccccbb
output:
8
result:
ok single line: '8'
Test #13:
score: 0
Accepted
time: 0ms
memory: 3872kb
input:
20 acccccbcbb bccbccaaac aabbcbbccb ababcabccb abcaabbcab ccabbabcca bbccaaacbc bbabacbccc babacbaacc bcabaacbac acbabaabbb caaccbacaa bccccbcbcc abbbbbbcbb bbcbaabaac abccaabccb cacacaccca bcbbcbcacc bcccaabcbc cabaaaccca
output:
9
result:
ok single line: '9'
Test #14:
score: 0
Accepted
time: 0ms
memory: 3956kb
input:
20 bcbbbababc baccababbc bcccbaacbc ccccacbaca aaaaccabbb cbbbacbaaa aaabbaabcb aacccbbacb bcbccbcacc caabacbcba bcbcbbcbbc cacccabcaa abbababacb aacaabbccb abbcacaccb caaccaacca bcbacacaac baccbcccbc abbcaccabb acbacccccb
output:
13
result:
ok single line: '13'
Test #15:
score: 0
Accepted
time: 0ms
memory: 3760kb
input:
20 babccbbbbc accacaabcb acacabaabb bacbccacac cacacaacaa cacaaaaaca bccbccacac acbaccabbb ccbacaccba acbaaababb ccacabcaaa bbabbcabcc bacbccccac bcacaacacc ccabcbbbaa aaababbbab bbbbbabbac abbcaabbbb bababbabac aaabcbbacb
output:
12
result:
ok single line: '12'
Test #16:
score: 0
Accepted
time: 0ms
memory: 3888kb
input:
20 aacbaacccb cbcbcacaaa cacbacbaca aabacccacb bbbcbacbcc cababcacaa bbcaaacbbc ccccacaaca cabcbcccaa bbcbccabbc ccababccca aaacbaabbb baacabacbc accbbcbbab cccbccabba cbccaaaaca cbcabaccca caaacbccca acaaabccab bbbaaabbac
output:
10
result:
ok single line: '10'
Test #17:
score: 0
Accepted
time: 0ms
memory: 3800kb
input:
20 aaacaacbcb cccccccaca abbabbcacb accaacbabb bacbaccbac cbcbbcccba bacbcabcac abaabcabab acaaacaaab bacbbaccac baababbbbc caaaaabaca abacaccacb abbbcbccbb cbcbcbbcaa cabbcaabba cbccbaccaa ccbbcabbaa ababababcb abcbcbcabb
output:
9
result:
ok single line: '9'
Test #18:
score: 0
Accepted
time: 0ms
memory: 3892kb
input:
20 bcaccbabbc caaaaccaca acbaacabab aaabbabbcb ccccaccaca bcacbaacbc cbccacabca ccbabbaaaa ababcbaaab caabacabca bbbcaabcac cccccababa aabbabcccb abaaaccbbb bcabaabbcc bcbbbaacac acaacbbccb bacabbabcc bbcbccbbac aacbabccbb
output:
7
result:
ok single line: '7'
Test #19:
score: 0
Accepted
time: 0ms
memory: 3808kb
input:
20 cbacccbaba caccbccaba abcaccacab cbcccabaca acccbccacb bccacbbabc bbacabacac abbcccbbab acaaaabbcb cbbbaabaca babbbccacc bbabccbcbc cabaababaa caacbabcba aaaaaacccb ccaaacacaa baccaabcac aaaacbcbab baacaaaabc ccabcacaba
output:
8
result:
ok single line: '8'
Test #20:
score: 0
Accepted
time: 0ms
memory: 3956kb
input:
20 bbaccaccbc cabcccabba bcabbbbaac caaacccaca cabccbabaa abccaaacab ababbccabb acccaaabab bababbcacc acabbacacb accccbcaab cabaaccbca cccacbbcca acabbaccab baacccacbc bacacabbcc aabaaaacab cbbabcccba aaaacbaccb cccbaaaaca
output:
12
result:
ok single line: '12'
Test #21:
score: 0
Accepted
time: 0ms
memory: 3888kb
input:
20 aabacacacb abaccaccbb acaccccbcb cbacbcccca cccccabbaa bbbcbabccc cabbccccba babcbcabac baccbaacbc ccbbccbbba aacaabbbab bccaccacac abbcacaccb cbcaabacba babbcbaacc ccabbbbbaa cbcbbbaaba bcaabcbaac bcbbbcbbbc babccbbbac
output:
13
result:
ok single line: '13'
Test #22:
score: 0
Accepted
time: 0ms
memory: 3808kb
input:
17 hydrogen nitrogen helium neon magnesium niobium molybdenum newdymnium holmium hafnium neptunium mendelevium nobelium hassium meitnerium nihonium moscovium
output:
6
result:
ok single line: '6'
Test #23:
score: 0
Accepted
time: 0ms
memory: 3956kb
input:
10 cbabbbcabb bacbacbcba bcacacacba bbabbbbbac acaccccbac bbbbababca bacabccaac aacbcaabcb bacbabaaaa acabcabccb
output:
3
result:
ok single line: '3'
Test #24:
score: 0
Accepted
time: 0ms
memory: 3876kb
input:
100 ccbcaccbab bbcbcbbbca acbbbbbcbb bacabcbcba aaaabcbaac babaaabbba bbbabbbabc bccaaacbac acacaccbaa acbacbcaac baccabcccb bbabcccbca acbabaaaac bcbbcabacc ccbbacbcbc aaaabcbcaa aacbbbaaaa bbabbcacac baabacbbcc abaccbabab abcbbabacb cbbbaccbcb bbabbcabca bcbaacacaa aabccaacca bcabaaacca acbcbacbbc...
output:
32
result:
ok single line: '32'
Test #25:
score: 0
Accepted
time: 0ms
memory: 3864kb
input:
1000 pfalakkgegzhogw wkkuxghywruwxfe wyejymxprfudmww pzfhykyprexdzjp euglzawfswzsicw wukfsntcitmqqsp ptedktsjhdybegp woiewjinnixhftw pwysrvatyqcgxcp pyslupqwmpqluzw ezwtyuflrtgjdle pyecuqzysscnqvp pualunhhvihcohe eemgrxaolvkxmup egvaujnrfthojvw ekfhcvufcqcrhcw ecqzrgboomfjcve whxlumclfpgcanw pfoxyrw...
output:
225
result:
ok single line: '225'
Test #26:
score: 0
Accepted
time: 0ms
memory: 3796kb
input:
30 rfiuianksyzpkqz zkntbrwccnjcnzh hvyhatniqoeptvh zzwxgtvocagvdlz hkvtotqsilzpexr rmqjlxhiyuvtwrh ziynrswzgzpnfnz rntoducfmkqpaoz rgzweicxeqajpzr zjznfxgpfgshkbr rmtmhwrzkenopsz hyodaehasivoabz hkgxlvuxonzlvgr hcjelcmekbohgxr zkdlkppyvchvimh rehlcscmhbnjexr rhhhexryikreroz htuwcazhktbrvqr hvnicynkr...
output:
11
result:
ok single line: '11'
Test #27:
score: 0
Accepted
time: 0ms
memory: 3964kb
input:
300 bzpjihkgvkrwzav bssiintigbaccyv asuzprjzymuwkfv blajmgohbmihtwb bwocwcqekqwuwab azkbjbrjdnwgzhb aqdgacdlcofzjzb vvqgvpdtsphhqbb vafommzgswakrub bizlmhzwvokxezb btwrjkdkxiaciaa bgyfvakbcgcaima vtkthaktjltsvtv vmyxovrkpphmnna bgwhfiinpdjigza vaghbpbabwfsnub atztqndgqetgbzv agtepkzcnnrlfzb ayktyzbv...
output:
196
result:
ok single line: '196'
Test #28:
score: 0
Accepted
time: 0ms
memory: 3892kb
input:
1000 drucrd dwbdnwzffwd dkcoffhuvxgzd dtd dbud dhdjamctkfkufpd dpolagked dqpyleydrcbjd diunguld dbpxmzd dd dllmgjsd dnncoucapnojd dbydsqd did dgjd dmd dkzkjmdkd derbbcjvtgxbgd dbpznlrtud dxrdhad dqhyxdd dgqd dawzjid domzfuycd dlyed dkunoduhamd dlpwoaqgjuwazd dcd dxnvgrvxnd drxptrhxd duqwvybjgahd djh...
output:
0
result:
ok single line: '0'
Test #29:
score: 0
Accepted
time: 0ms
memory: 3796kb
input:
18 aab bac caa abb bbc cba acb bcc cca adb bdc cda aeb bec cea afb bfc cfa
output:
0
result:
ok single line: '0'
Test #30:
score: 0
Accepted
time: 0ms
memory: 3876kb
input:
1000 qqaligwjiggjcq iagxuiizhglmi xuikcxsrirevfi qgcyddrpx iriauckx xaq iczi xqhfnkhgx ihjmwpzmaplimcq qxhadplhx qylxcygq xi xansoq injixpfhfasvbq qiwgbci xjgmxhtxvdq iihmigcihi iedrdwzgq iyi xhqlttzyni qcx irbnlx qmcxdihujwlai iqaq qyhquti qcqzoifzglwxzdq ikjajeafi ifgydi xembxgcluzqq qyesjwiix qkx...
output:
242
result:
ok single line: '242'
Test #31:
score: 0
Accepted
time: 0ms
memory: 3888kb
input:
100 yhothsuntodvjbp yovbflgbufdystp plxhiphtvtvccxn yteszfwnocvquep yimksvuvxrmquyn yzxolkjfnwdwcop yvnzximnjfteqap padrxvamipryowy pxgkjkpddfbrarn ykqtkdxxwzknrvp pxewmovejzktyzn pnnjanibbinhwzn ylzdwvrozhyyyen yfyfqvvuycfaxpp nechefkhfvumkry yvtzpokomrtusyn pwpbgmtkpcnhmtn niyymfgohdgdhuy yedcxgnr...
output:
67
result:
ok single line: '67'
Test #32:
score: 0
Accepted
time: 0ms
memory: 3888kb
input:
1000 yaswiedrkfymnzk kzcaleacmpuazhv kfefxdppxusoqxv vifosydgwnqpssk ymtrrddmufmncfv vrupdvcsmepqtwk vjuvfllbidvbcqy veldskdioyyzock kdmjepctwkiixrv ypicbokwooycocv ybbsmccvqynbvwk yzgsbzbhteyajfk yyynqadclcjkcvv kmwrrremazrcdyv yfuauavqsoxnknv yizrfjukexccyvk yuodugxjnuymgwv vvdbmcmdcejdjhk vsesegg...
output:
360
result:
ok single line: '360'
Test #33:
score: 0
Accepted
time: 0ms
memory: 3952kb
input:
30 nduqkltyrjchrir npqnyjhvtczrxhk rvkhqwigvnjasln nqxnnyxpmhbzhrr kcrjplhrdkyyvpn nuxuodpvfvyovsk nzcbwoxvmuajnuk rcrqzqtykuzgiek rvzjffzzwapzvck rgntauijiodjcwn nqntaykdmrpiojr kmbynsfeerniqpr rszawhpanrairqk nhjsfdswnnaqumr kijysjjlrbwigin njebshbbcadcbwk ncwluvybyxhbuvr rlxuzfjuxgziehk rcbtttxlq...
output:
11
result:
ok single line: '11'
Test #34:
score: 0
Accepted
time: 0ms
memory: 3884kb
input:
300 ldqparrlixcrfhn lslzwfkysvvvaqt lklydecymfdsymn nxxolcshfdiofxt lkwqujbckqmigin nfqvomhsapqexsl njnqzhjetlnecwt twgomlfjreikycl lujnrxtaognjjbn lciyasqkkkcgrln ncwhdddgamnbgft naprkvnqkxqjdjl ttltucizicrybgl trdnzylpxeujmql nmyusbfdjyaoaft lsdwoewrtnrxhkn nfapnyvwftbnwyl lvahwwkijbffrxn tzmuasjd...
output:
107
result:
ok single line: '107'