Task: | Median string |
Sender: | Game of Nolife |
Submission time: | 2017-05-27 12:25:20 +0300 |
Language: | C++ |
Status: | READY |
Result: | ACCEPTED |
test | verdict | time | |
---|---|---|---|
#1 | ACCEPTED | 0.07 s | details |
#2 | ACCEPTED | 0.06 s | details |
#3 | ACCEPTED | 0.06 s | details |
#4 | ACCEPTED | 0.05 s | details |
#5 | ACCEPTED | 0.18 s | details |
#6 | ACCEPTED | 0.05 s | details |
#7 | ACCEPTED | 0.03 s | details |
#8 | ACCEPTED | 0.05 s | details |
#9 | ACCEPTED | 0.04 s | details |
#10 | ACCEPTED | 0.05 s | details |
#11 | ACCEPTED | 0.06 s | details |
#12 | ACCEPTED | 0.07 s | details |
#13 | ACCEPTED | 0.04 s | details |
#14 | ACCEPTED | 0.03 s | details |
#15 | ACCEPTED | 0.05 s | details |
#16 | ACCEPTED | 0.04 s | details |
#17 | ACCEPTED | 0.06 s | details |
#18 | ACCEPTED | 0.05 s | details |
#19 | ACCEPTED | 0.06 s | details |
#20 | ACCEPTED | 0.06 s | details |
#21 | ACCEPTED | 0.04 s | details |
#22 | ACCEPTED | 0.04 s | details |
#23 | ACCEPTED | 0.04 s | details |
#24 | ACCEPTED | 0.06 s | details |
#25 | ACCEPTED | 0.06 s | details |
#26 | ACCEPTED | 0.17 s | details |
#27 | ACCEPTED | 0.18 s | details |
#28 | ACCEPTED | 0.14 s | details |
#29 | ACCEPTED | 0.18 s | details |
#30 | ACCEPTED | 0.13 s | details |
#31 | ACCEPTED | 0.15 s | details |
#32 | ACCEPTED | 0.13 s | details |
#33 | ACCEPTED | 0.15 s | details |
#34 | ACCEPTED | 0.14 s | details |
#35 | ACCEPTED | 0.14 s | details |
#36 | ACCEPTED | 0.17 s | details |
#37 | ACCEPTED | 0.17 s | details |
#38 | ACCEPTED | 0.15 s | details |
#39 | ACCEPTED | 0.15 s | details |
#40 | ACCEPTED | 0.14 s | details |
#41 | ACCEPTED | 0.14 s | details |
#42 | ACCEPTED | 0.16 s | details |
#43 | ACCEPTED | 0.13 s | details |
#44 | ACCEPTED | 0.12 s | details |
#45 | ACCEPTED | 0.18 s | details |
Code
#include <bits/stdc++.h> #define F first #define S second #define X real() #define Y imag() using namespace std; typedef long long ll; typedef long double ld; struct fro{ int a,b,c; char ch; }; int dp[55][55][55]; fro dpf[55][55][55]; void go(int a, int b, int c, int v, fro f){ if (v<dp[a][b][c]){ dp[a][b][c]=v; dpf[a][b][c]=f; } } int main(){ ios_base::sync_with_stdio(0); cin.tie(0); string a,b,c; cin>>a>>b>>c; int as=a.size(); int bs=b.size(); int cs=c.size(); for (int i=0;i<=as;i++){ for (int ii=0;ii<=bs;ii++){ for (int iii=0;iii<=cs;iii++){ dp[i][ii][iii]=1e9; } } } dp[0][0][0]=0; for (int i=0;i<=as;i++){ for (int ii=0;ii<=bs;ii++){ for (int iii=0;iii<=cs;iii++){ int tc=dp[i][ii][iii]; for (int j=0;j<8;j++){ int ni=i; int nii=ii; int niii=iii; if ((j&1)>0&&i==as) continue; else if (j&1) ni=i+1; if ((j&2)>0&&ii==bs) continue; else if (j&2) nii=ii+1; if ((j&4)>0&&iii==cs) continue; else if (j&4) niii=iii+1; for (char ch='A';ch<='Z';ch++){ int co=0; if ((j&1)>0){ if (a[i]!=ch) co++; } else co++; if ((j&2)>0){ if (b[ii]!=ch) co++; } else co++; if ((j&4)>0){ if (c[iii]!=ch) co++; } else co++; go(ni, nii, niii, tc+co, {i, ii, iii, ch}); } go(ni, nii, niii, tc+__builtin_popcount(j), {i, ii, iii, ' '}); } } } } int be=1e9; int bea=0; int beb=0; int bec=0; for (int i=0;i<=as;i++){ for (int ii=0;ii<=bs;ii++){ for (int iii=0;iii<=cs;iii++){ int ac=as-i+bs-ii+cs-iii; if (dp[i][ii][iii]+ac<be){ be=dp[i][ii][iii]+ac; bea=i; beb=ii; bec=iii; } } } } string ans; while (bea>0||beb>0||bec>0){ // cout<<bea<<" "<<beb<<" "<<bec<<endl; if (dpf[bea][beb][bec].ch!=' ') ans+=dpf[bea][beb][bec].ch; int na=dpf[bea][beb][bec].a; int nb=dpf[bea][beb][bec].b; int nc=dpf[bea][beb][bec].c; bea=na; beb=nb; bec=nc; } reverse(ans.begin(), ans.end()); cout<<ans<<endl; }
Test details
Test 1
Verdict: ACCEPTED
input |
---|
A A A |
correct output |
---|
A |
user output |
---|
A |
Test 2
Verdict: ACCEPTED
input |
---|
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA... |
correct output |
---|
A |
user output |
---|
A |
Test 3
Verdict: ACCEPTED
input |
---|
A AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA... |
correct output |
---|
A |
user output |
---|
A |
Test 4
Verdict: ACCEPTED
input |
---|
A A AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA... |
correct output |
---|
A |
user output |
---|
A |
Test 5
Verdict: ACCEPTED
input |
---|
EEBAKAUUFWHXAHYEANNASFUDNDZXXL... |
correct output |
---|
EGBAKBBMFTHFJHEAKDASLFHBNZGXVM... |
user output |
---|
EGBBKAMBEMHFJHEAKDASLFHBNZIAVB... |
Test 6
Verdict: ACCEPTED
input |
---|
BABAAAAB BBAAAAAAB BBBABABB |
correct output |
---|
BBABAAAAB |
user output |
---|
BABAAAAB |
Test 7
Verdict: ACCEPTED
input |
---|
AAAAA AAABAAA BBAAAA |
correct output |
---|
AAAAAA |
user output |
---|
AAAAA |
Test 8
Verdict: ACCEPTED
input |
---|
AABAABB ABAAAB BBABAABA |
correct output |
---|
ABABAABA |
user output |
---|
ABABAAB |
Test 9
Verdict: ACCEPTED
input |
---|
BAABAB BBAAABAAAA ABAAABBB |
correct output |
---|
BBAAABAB |
user output |
---|
ABAAABAB |
Test 10
Verdict: ACCEPTED
input |
---|
BABAB AABABBBA BABABBB |
correct output |
---|
BABABBB |
user output |
---|
BABABBB |
Test 11
Verdict: ACCEPTED
input |
---|
AAABBBABBB BABBABABB ABBBB |
correct output |
---|
AABBBABB |
user output |
---|
AABBBABB |
Test 12
Verdict: ACCEPTED
input |
---|
AABAAABBAA BABAB BBBAA |
correct output |
---|
BABBAA |
user output |
---|
BBBAA |
Test 13
Verdict: ACCEPTED
input |
---|
BBBBBBBBA AABABAABA ABBBAAA |
correct output |
---|
ABBBBAABA |
user output |
---|
AABBBAABA |
Test 14
Verdict: ACCEPTED
input |
---|
BABBBABAA AABBBBABB AABBBAB |
correct output |
---|
AABBBABA |
user output |
---|
AABBBAB |
Test 15
Verdict: ACCEPTED
input |
---|
ABBBBBBB ABBABABBA BBBBABBBA |
correct output |
---|
ABBBBABBBA |
user output |
---|
ABBBABBB |
Test 16
Verdict: ACCEPTED
input |
---|
BBABABAB BBBBBA AABAAA |
correct output |
---|
BBABABA |
user output |
---|
BABABA |
Test 17
Verdict: ACCEPTED
input |
---|
AAABAAAA ABABAB BBBBBBB |
correct output |
---|
ABABABA |
user output |
---|
ABABAB |
Test 18
Verdict: ACCEPTED
input |
---|
BBABABA BABAAAABAA BABBB |
correct output |
---|
BABABABA |
user output |
---|
BBABABA |
Test 19
Verdict: ACCEPTED
input |
---|
AABBABB BBBBAABBBA BAABBAA |
correct output |
---|
BAABBABA |
user output |
---|
BAABBAA |
Test 20
Verdict: ACCEPTED
input |
---|
BBBBBAA AAABAAAA AAABBABB |
correct output |
---|
AAABBAAA |
user output |
---|
AAABBAA |
Test 21
Verdict: ACCEPTED
input |
---|
AAAABBA ABAABA BBABBBBBA |
correct output |
---|
ABAABBA |
user output |
---|
ABAABBA |
Test 22
Verdict: ACCEPTED
input |
---|
BBBABAB ABBABBBAA ABBBAABABB |
correct output |
---|
ABBBABAB |
user output |
---|
ABBBABAB |
Test 23
Verdict: ACCEPTED
input |
---|
BBAAA BBABAB ABBBBABBB |
correct output |
---|
BBABAB |
user output |
---|
BBABAB |
Test 24
Verdict: ACCEPTED
input |
---|
AABABBBAAB BBBABBBA ABBAAAB |
correct output |
---|
ABBABBBAAB |
user output |
---|
ABBABBBA |
Test 25
Verdict: ACCEPTED
input |
---|
ABBBBBBBB BAABAABAAA BAAAABAAAB |
correct output |
---|
BAABAABAAAB |
user output |
---|
BAABAABAAA |
Test 26
Verdict: ACCEPTED
input |
---|
BBDDCBBCDBAABAACBAADACABBDDABB... |
correct output |
---|
BADACCBCDBADBAACBAADACBABBCABB... |
user output |
---|
BADACCBCDBADBABAACBBAACACABBCD... |
Test 27
Verdict: ACCEPTED
input |
---|
ADCDADBDDDCACBCCBCACDCDBCBCDBB... |
correct output |
---|
DCAADADCDACBDBBDABDCCDBCABCBAC... |
user output |
---|
DCAADADCDACBDBBDABCCCDBCBCBACA... |
Test 28
Verdict: ACCEPTED
input |
---|
CBCBABACDDACDCBCBBBADACDCDCBCA... |
correct output |
---|
DCACBABDCABCCACBCCBCBADABCDDCC... |
user output |
---|
DCACBABDCBCACBCCBCBADBCDDCCABA... |
Test 29
Verdict: ACCEPTED
input |
---|
CCBADBAACDDCBAABCADBDBDCCBCCDC... |
correct output |
---|
CABCBBABBDBAAACBDDABDAABCABBDB... |
user output |
---|
CABCBBABBDBAAACBDDABAABBCAABDB... |
Test 30
Verdict: ACCEPTED
input |
---|
DCBDBABAADBDCDCDDDCCDACADDCCAC... |
correct output |
---|
DCBABACDDBACDCBDDACAACADDCCACD... |
user output |
---|
DBABACADDBCCDCBDDACAACADDCCACD... |
Test 31
Verdict: ACCEPTED
input |
---|
BCBACAADABAACACADCADCDAAACDDDD... |
correct output |
---|
BCDCCBADDBBACDCADCDAADACDBDADA... |
user output |
---|
BCDCCAADDBBACDCADCDAADACDBDADA... |
Test 32
Verdict: ACCEPTED
input |
---|
ACDCDACCABADADABADDAAACBDCABBB... |
correct output |
---|
ACDADACCABABACABADAABACBDCABBA... |
user output |
---|
ACDADACCABABAAABADBAAACBDCABBD... |
Test 33
Verdict: ACCEPTED
input |
---|
ABCCDCADCDADAADBDDBBABDACBBAAC... |
correct output |
---|
BCDADCDBABDBDDCBDABDACBBAAADCA... |
user output |
---|
BCDADCDDABDBDCBDABDACBBAAADCAB... |
Test 34
Verdict: ACCEPTED
input |
---|
DABDBACDBADABBDDBAACCAADABDBBD... |
correct output |
---|
DABDCBACADBDADCAABDBDBAACDAADA... |
user output |
---|
DABDCBAACDBDACAABDBDBABACDAADA... |
Test 35
Verdict: ACCEPTED
input |
---|
BCBABDCADCBADCAABCACCBDAABBCBD... |
correct output |
---|
BCBDBDCADBBBBCCABCDADBDAADBCBD... |
user output |
---|
BCBDBCADBBBBCCABCDADBDAADBCBDB... |
Test 36
Verdict: ACCEPTED
input |
---|
TFWRLHNANNYROWCGQJUHNIAHQTQMJF... |
correct output |
---|
TFCRBHJANDNYJOCGQPJAHNIACFJCMJ... |
user output |
---|
TFCRBDJANDNYJOCGQPJAHNIACFJCMJ... |
Test 37
Verdict: ACCEPTED
input |
---|
HLQGBFZAPEMVFIDMBTZLKOSTCSBKPX... |
correct output |
---|
HKVGBAKAWEACFIBHCMNBTALCLSTSBJ... |
user output |
---|
PKAGBAPEUOFACMBTYGWNSTCDLKPXNH... |
Test 38
Verdict: ACCEPTED
input |
---|
BURAOHCWCRFABWYQTGIDCIJZGAGOQH... |
correct output |
---|
BUMIHPWFBAAMWREPGDCIJIGGGQHJAJ... |
user output |
---|
BUMIHPWFBAAMWREPGDCIJIGGGQHJCL... |
Test 39
Verdict: ACCEPTED
input |
---|
JHLXFPNXFCWAXXBNOOKKAAOYCAJQNC... |
correct output |
---|
FHPNDFCWABLINDFGCAAFYCMJNCCHYE... |
user output |
---|
FHPNDFCWABLINHICGAAFYCMJNCCHYE... |
Test 40
Verdict: ACCEPTED
input |
---|
XPRJAEQNVMRJPRONUEBLIRWTWQLPCT... |
correct output |
---|
XRIAEFBHMDICDNJEBLIJDTHQCXRNAA... |
user output |
---|
XRIAEFBHMDICDNJEBLIJETHQCXRNAA... |
Test 41
Verdict: ACCEPTED
input |
---|
LIFBDNCQAUIBFDBQWYQYHHIHTILAGL... |
correct output |
---|
GLGNIKBDNSQAJIUDBJYFIILAGJCEAK... |
user output |
---|
GLGNIKBDNSQAJIUDBJYFIILAGJCEAK... |
Test 42
Verdict: ACCEPTED
input |
---|
XVRPEIHNUVILHOMUZVSDUBCCWFCUPR... |
correct output |
---|
XHJPIADTKEFHOUZSDUYCBAFCAHBGEU... |
user output |
---|
XHJPIADUTEFHOUZDRDUBCCAFCAHBGE... |
Test 43
Verdict: ACCEPTED
input |
---|
NVXEUOKZUBIPREENTXKZNJCKOJWSZX... |
correct output |
---|
NVEUJFZJNGPJUEVTJHNJCKOAWSFZUA... |
user output |
---|
FNHXEUIVZJNGPAJDLOPKZAJCKYTKFZ... |
Test 44
Verdict: ACCEPTED
input |
---|
TPMZYIOLFNHUYUTQEGXKDUVWIIGPZR... |
correct output |
---|
TEDBKIWELFIHKUYBOANEGDCBJIBBEZ... |
user output |
---|
TEDBKIWLFFEUYKOQEGAKOIEWIBBPUR... |
Test 45
Verdict: ACCEPTED
input |
---|
OPTIBHSPIKWOVIIAJSDRGAHPPSWHGZ... |
correct output |
---|
BHSPICWOJIIENAGODCGAHKGDWHGCAB... |
user output |
---|
BHSPICWOJILEIAGODCGAHKGDWHGCAB... |