CSES - HIIT Open 2017 - Results
Submission details
Task:Median string
Sender:Game of Nolife
Submission time:2017-05-27 12:25:20 +0300
Language:C++
Status:READY
Result:ACCEPTED
Test results
testverdicttime
#1ACCEPTED0.07 sdetails
#2ACCEPTED0.06 sdetails
#3ACCEPTED0.06 sdetails
#4ACCEPTED0.05 sdetails
#5ACCEPTED0.18 sdetails
#6ACCEPTED0.05 sdetails
#7ACCEPTED0.03 sdetails
#8ACCEPTED0.05 sdetails
#9ACCEPTED0.04 sdetails
#10ACCEPTED0.05 sdetails
#11ACCEPTED0.06 sdetails
#12ACCEPTED0.07 sdetails
#13ACCEPTED0.04 sdetails
#14ACCEPTED0.03 sdetails
#15ACCEPTED0.05 sdetails
#16ACCEPTED0.04 sdetails
#17ACCEPTED0.06 sdetails
#18ACCEPTED0.05 sdetails
#19ACCEPTED0.06 sdetails
#20ACCEPTED0.06 sdetails
#21ACCEPTED0.04 sdetails
#22ACCEPTED0.04 sdetails
#23ACCEPTED0.04 sdetails
#24ACCEPTED0.06 sdetails
#25ACCEPTED0.06 sdetails
#26ACCEPTED0.17 sdetails
#27ACCEPTED0.18 sdetails
#28ACCEPTED0.14 sdetails
#29ACCEPTED0.18 sdetails
#30ACCEPTED0.13 sdetails
#31ACCEPTED0.15 sdetails
#32ACCEPTED0.13 sdetails
#33ACCEPTED0.15 sdetails
#34ACCEPTED0.14 sdetails
#35ACCEPTED0.14 sdetails
#36ACCEPTED0.17 sdetails
#37ACCEPTED0.17 sdetails
#38ACCEPTED0.15 sdetails
#39ACCEPTED0.15 sdetails
#40ACCEPTED0.14 sdetails
#41ACCEPTED0.14 sdetails
#42ACCEPTED0.16 sdetails
#43ACCEPTED0.13 sdetails
#44ACCEPTED0.12 sdetails
#45ACCEPTED0.18 sdetails

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...