QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#96561 | #5577. Alchemy | PetroTarnavskyi# | AC ✓ | 3ms | 3408kb | C++17 | 1.1kb | 2023-04-14 15:28:42 | 2023-04-14 15:28:46 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define SZ(a) (int)a.size()
#define ALL(a) a.begin(), a.end()
#define FOR(i, a, b) for (int i = (a); i<(b); ++i)
#define RFOR(i, b, a) for (int i = (b)-1; i>=(a); --i)
#define MP make_pair
#define PB push_back
#define F first
#define S second
typedef long long LL;
typedef pair<int, int> PII;
typedef vector<int> VI;
const int N = 107;
void updMin(int& x, int val) {
x = min(x, val);
}
int dp[N][2][2];
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
string s;
cin >> s;
int n = SZ(s);
RFOR(i, n / 2, 0) {
int l = i, r = n - 1 - i;
FOR(cl, 0, 2) FOR(cr, 0, 2) {
dp[i][cl][cr] = N;
FOR(dl, 0, 2) FOR(dr, 0, 2) {
if ((s[l] == s[r] && ((cl || dl) == (cr || dr))) || (s[l] != s[r] && (cl || dl || cr || dr))) {
if (n % 2 == 0 && i == n / 2 - 1) {
if (dl == dr) {
updMin(dp[i][cl][cr], dl);
}
}
else {
updMin(dp[i][cl][cr], dp[i + 1][dl][dr] + dl + dr);
}
}
}
}
}
cout << dp[0][0][0] << "\n";
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 2ms
memory: 3284kb
input:
ioi
output:
0
result:
ok single line: '0'
Test #2:
score: 0
Accepted
time: 1ms
memory: 3340kb
input:
noi
output:
1
result:
ok single line: '1'
Test #3:
score: 0
Accepted
time: 2ms
memory: 3356kb
input:
ctsc
output:
1
result:
ok single line: '1'
Test #4:
score: 0
Accepted
time: 2ms
memory: 3336kb
input:
fool
output:
2
result:
ok single line: '2'
Test #5:
score: 0
Accepted
time: 0ms
memory: 3280kb
input:
vetted
output:
2
result:
ok single line: '2'
Test #6:
score: 0
Accepted
time: 0ms
memory: 3324kb
input:
aa
output:
0
result:
ok single line: '0'
Test #7:
score: 0
Accepted
time: 2ms
memory: 3284kb
input:
ic
output:
1
result:
ok single line: '1'
Test #8:
score: 0
Accepted
time: 1ms
memory: 3404kb
input:
tlffohemdcncrfrxaqsbzcoyodvbxmhqukvfpahnakexcmacqa
output:
12
result:
ok single line: '12'
Test #9:
score: 0
Accepted
time: 2ms
memory: 3304kb
input:
qrgld
output:
1
result:
ok single line: '1'
Test #10:
score: 0
Accepted
time: 2ms
memory: 3356kb
input:
ejyfprguvwrnrsrykyrotmdjuzroohvlxqhvyeukkvmshtpczyyecpzhsqvkxueqvhlxldhofrzcjdhtotykgrsdnrnvuyrphyjy
output:
26
result:
ok single line: '26'
Test #11:
score: 0
Accepted
time: 2ms
memory: 3384kb
input:
xcpccpcy
output:
2
result:
ok single line: '2'
Test #12:
score: 0
Accepted
time: 2ms
memory: 3316kb
input:
abpccpcp
output:
1
result:
ok single line: '1'
Test #13:
score: 0
Accepted
time: 2ms
memory: 3284kb
input:
ixpccpci
output:
2
result:
ok single line: '2'
Test #14:
score: 0
Accepted
time: 1ms
memory: 3348kb
input:
xcxccpci
output:
2
result:
ok single line: '2'
Test #15:
score: 0
Accepted
time: 1ms
memory: 3348kb
input:
xcpxcpci
output:
3
result:
ok single line: '3'
Test #16:
score: 0
Accepted
time: 1ms
memory: 3352kb
input:
ixxccpci
output:
1
result:
ok single line: '1'
Test #17:
score: 0
Accepted
time: 0ms
memory: 3284kb
input:
ixpxcpci
output:
2
result:
ok single line: '2'
Test #18:
score: 0
Accepted
time: 2ms
memory: 3284kb
input:
ixpxxycpci
output:
3
result:
ok single line: '3'
Test #19:
score: 0
Accepted
time: 2ms
memory: 3332kb
input:
yxxxyxxxxxyyxxyxxyxyyyxyxyyyyxyxxxxxxxxxxxxyyxxyxyxyyxxyyxyxxyyxxyyyyyyxxyyxxyyxxxxyyyxxxyyxyxyxxyxx
output:
19
result:
ok single line: '19'
Test #20:
score: 0
Accepted
time: 2ms
memory: 3344kb
input:
caacbbacc
output:
2
result:
ok single line: '2'
Test #21:
score: 0
Accepted
time: 1ms
memory: 3328kb
input:
xjnfkxxjfnjx
output:
2
result:
ok single line: '2'
Test #22:
score: 0
Accepted
time: 2ms
memory: 3384kb
input:
baabaaa
output:
2
result:
ok single line: '2'
Test #23:
score: 0
Accepted
time: 0ms
memory: 3400kb
input:
bbaccaabcabca
output:
3
result:
ok single line: '3'
Test #24:
score: 0
Accepted
time: 0ms
memory: 3340kb
input:
ozo
output:
0
result:
ok single line: '0'
Test #25:
score: 0
Accepted
time: 2ms
memory: 3316kb
input:
zoooo
output:
2
result:
ok single line: '2'
Test #26:
score: 0
Accepted
time: 0ms
memory: 3404kb
input:
zooooo
output:
2
result:
ok single line: '2'
Test #27:
score: 0
Accepted
time: 2ms
memory: 3272kb
input:
ccclcclllclllcllcccccclclclclccccccllllllclccclcccllclclcllcllcllccllcllclccllclcclcclclllclllclclcc
output:
16
result:
ok single line: '16'
Test #28:
score: 0
Accepted
time: 2ms
memory: 3296kb
input:
hhzhhhhzzzzhzhzzzhhzzhzzzzhzzhhzhzhhzhhhzzhzzhzzzzhzzzzhzhzhzhzzhhhhzhzzhzhhhzzzhzzhhzzhzzzzhhhzhhzz
output:
22
result:
ok single line: '22'
Test #29:
score: 0
Accepted
time: 1ms
memory: 3348kb
input:
vaaaaaaavvavvaaaaavvavavavvvvvavavvvvvavvvvaavaavavvvvavavvvvavvavvvavvvvvvvavvvavaaavavvaaaavaavvaa
output:
18
result:
ok single line: '18'
Test #30:
score: 0
Accepted
time: 0ms
memory: 3408kb
input:
pjppjjpjpjjpjppjpppjpjjjjjppjjpjppjpjpppjjjppppjpjpjjjpjpjppjpppjjpppppjpjpjjpjjjppjjjpjjjjjpjpjjppj
output:
20
result:
ok single line: '20'
Test #31:
score: 0
Accepted
time: 2ms
memory: 3284kb
input:
xxxlllxllllxlxlxllxlxlxxlxxlxxllxlxxxlxlxllxxllxllxxlxxlxxlllxxxlxxlllxxxlllllxxxxxxxlxlllxxlxlxllll
output:
20
result:
ok single line: '20'
Test #32:
score: 0
Accepted
time: 2ms
memory: 3356kb
input:
gggggvgvgggggvggvggggvvgvgvvgvggvggvgvvgvgvvvvvgvggvvgvgvvvgvvgggvvgggvgggggvggggggvvvggvggggvvgvggg
output:
17
result:
ok single line: '17'
Test #33:
score: 0
Accepted
time: 2ms
memory: 3284kb
input:
vvvbbvvbbvvbbvbvbbbbbbvbvvvbvvbbvbbvvvbbbvbvbbvbvbbvbbvvvbvbbbvbvbbbbbvbbvvvbbbbbvbvvbvvbvbbbbvbbvbb
output:
18
result:
ok single line: '18'
Test #34:
score: 0
Accepted
time: 2ms
memory: 3388kb
input:
ooooeeeeoeoeeoooeeeeeeoooeoooooeeoeoooeeoeeeoeooeooeeeooeeeeoooeeeoooeeeoooooooeoeoeeoeeoooeeooeoooe
output:
20
result:
ok single line: '20'
Test #35:
score: 0
Accepted
time: 2ms
memory: 3324kb
input:
fvfvvffvvfffvfvfffvfvfffffvvvfvfffvffvffvvvfvffvffvffvvfvfffvfvvvfvfvfvfvfvfvffvfvffvffvfvvvfvfffvfv
output:
19
result:
ok single line: '19'
Test #36:
score: 0
Accepted
time: 1ms
memory: 3388kb
input:
vvvnvnnnvnvvvnvnvvvvvnvvnnvnnvnnvvvnvnnvvvnvvnvnnnvnnnnnvvvnnvnvnnvnnvvnnvnnvnvvvvnvvnnnnvvvnnvnnnvn
output:
20
result:
ok single line: '20'
Test #37:
score: 0
Accepted
time: 2ms
memory: 3284kb
input:
vxvexexxexxvvexxeexexvvvxexxxvxeevxeevvexvevxevexevxxvvevvevexexeeexxexvxexeexvxexvevxxxxxxxeevvexev
output:
22
result:
ok single line: '22'
Test #38:
score: 0
Accepted
time: 2ms
memory: 3284kb
input:
fssfkffsfsssffffsskfssssfkffkfksfkssfsffkkfffssksskfkskkkkkkfffffkkkfkkfffffkfsssskkssfksffffffffkff
output:
21
result:
ok single line: '21'
Test #39:
score: 0
Accepted
time: 0ms
memory: 3304kb
input:
effyeyyeeyeefefyeyfffeeeffffyfyefyeyyyfefeffyefyyefyyfyfffyyfyfefefyfyeffyffeyfeefffyyeeeyfyyeffeffy
output:
22
result:
ok single line: '22'
Test #40:
score: 0
Accepted
time: 1ms
memory: 3272kb
input:
attftftaatataftfaftfftffaaafatafattffatfffattatattttffttaffaftaftafffaffatttatatftaafattttffaffttfff
output:
21
result:
ok single line: '21'
Test #41:
score: 0
Accepted
time: 2ms
memory: 3276kb
input:
dxdttddxxtdxxddxxxtdxtdtddtddttxxddddxxdxddttxdxdtttddtdxttdtdxxttdxtxxxtxxdtxxdxtxdtdtxdxttdttxxxxd
output:
21
result:
ok single line: '21'
Test #42:
score: 0
Accepted
time: 2ms
memory: 3392kb
input:
etetetextttxetteexeetttteeetxeeeexxeeettexeteteeexetxtexxxexeeetexxxttxetttxetxetetxxxeexxteteexextt
output:
25
result:
ok single line: '25'
Test #43:
score: 0
Accepted
time: 2ms
memory: 3396kb
input:
cuccddddcuccduuduccdducdcudcdccducdcccccduucdducccuuucddcdccdudddcccddudcdcdududuccdudduduucdduddddu
output:
21
result:
ok single line: '21'
Test #44:
score: 0
Accepted
time: 0ms
memory: 3360kb
input:
eeleleeljljjellejjlejjleelljllllllleljljllelejjeeelllejjjjljeeejjleljlelleejjejeleeleeljejejjjejelee
output:
23
result:
ok single line: '23'
Test #45:
score: 0
Accepted
time: 2ms
memory: 3332kb
input:
kkkvkyvvkykkkkyyyvkyyvvyyvvykvkkvvvyvyyyvykkykyyvvkvvyyyykkkyvkykvyyyvkyvkkkkkkkvvvkvvyvvkkkkkyvvkvv
output:
23
result:
ok single line: '23'
Test #46:
score: 0
Accepted
time: 2ms
memory: 3268kb
input:
fddfftftfdfffdtttdfdffddtdffdtffftdfdffftddddffdddffddtddftfttdtfdtffdftttdtdfdfdddttffftdtfddtttfft
output:
19
result:
ok single line: '19'
Test #47:
score: 0
Accepted
time: 2ms
memory: 3360kb
input:
aoaoaoaaaoaaoaoaoaooaoaoaaooaoaaooaaoooaooaooaaoaooaaaaaoooooaaoaoaoaaaoooaaaooaaaaaaooooaaaaaaaaoo
output:
21
result:
ok single line: '21'
Test #48:
score: 0
Accepted
time: 1ms
memory: 3268kb
input:
yyyyydddyyddyyydddyddddyyyyyyddydydyddyddyydyddddyyddddyyddyyydyddyddddyydyyydddddyddyydddddyyyddyy
output:
20
result:
ok single line: '20'
Test #49:
score: 0
Accepted
time: 2ms
memory: 3272kb
input:
eaeeaaaaeaaeaaaaeeeeaeaeaaaeaeeeaeaaaaaeeaaaeaaeeaaaeeaeeeeaeaeaeaeeaeeaaeaeeaaeaeeaaaeeeeeaaeeaaaa
output:
22
result:
ok single line: '22'
Test #50:
score: 0
Accepted
time: 1ms
memory: 3384kb
input:
yeeyyyyeyyyeyyeeyyyeeyyeeeyyeeyyyeeeeeeyeeyyeeyyeeyyyyeyeeeeeyeyeyeyyeyyyeeeeeeyyeyyeyyyyyyeyyeyeye
output:
21
result:
ok single line: '21'
Test #51:
score: 0
Accepted
time: 2ms
memory: 3272kb
input:
mummmuumuummmuuumumuumummmumumuumuuuuumumuuuumummummmumuummuumummmumuuummmmuummumummuuuuummuumuuumu
output:
22
result:
ok single line: '22'
Test #52:
score: 0
Accepted
time: 1ms
memory: 3324kb
input:
cnnnncncncnccnncnncncccnnccnccnncccnnncccnccccnncnnnnncccnccccnnncccccnccncncncccccncnncnccncnccnnc
output:
18
result:
ok single line: '18'
Test #53:
score: 0
Accepted
time: 2ms
memory: 3284kb
input:
iiirriiirriiiriirrririrrriiririirriiriiriiiirrririrrrrrriirrriiiirriiiiiiiriiiirrririiriiiiirririrr
output:
17
result:
ok single line: '17'
Test #54:
score: 0
Accepted
time: 2ms
memory: 3272kb
input:
kkkkkkekeekkeekekkkeeekkkekeekeekkkeeeeekkekkeekekkekkkeeekeeekeeekkkkkkekkeekkekkekekkeeeekekekeek
output:
19
result:
ok single line: '19'
Test #55:
score: 0
Accepted
time: 3ms
memory: 3360kb
input:
gdddggdddggdddddgggddgdddgggdddgdgdggdgddgdddddgggggddddggggddddgddgdgddgddgggdgdgggddggdgdgddgdgdg
output:
19
result:
ok single line: '19'
Test #56:
score: 0
Accepted
time: 0ms
memory: 3308kb
input:
piipippppippiiiippiiipppiipppiiiiipiippiiiipiipipiiippppippipipippppipiipppippippppipiipippppiipipp
output:
18
result:
ok single line: '18'
Test #57:
score: 0
Accepted
time: 0ms
memory: 3332kb
input:
kfppkkfkpfkppffpppffkkfkpppfkpppppkkfffkkfppfffkfpppkppffpfpkffkkppppkpffpkpkpkkkfkpkfkkpkpkpfkpkpk
output:
19
result:
ok single line: '19'
Test #58:
score: 0
Accepted
time: 1ms
memory: 3272kb
input:
ggaaaamggmmgaagagaagmgggmamgggmmammmaaggggmaaaaggagmmmgmaaggagagmaaammmmammgagmgamgagaaamggaamgagga
output:
21
result:
ok single line: '21'
Test #59:
score: 0
Accepted
time: 2ms
memory: 3404kb
input:
phhnphhnphnphhnnpnhpppnnhnnpphnpnnhhhphnpnnhnpnpphphhhhpphnphnnpphpnhnhnhhhnphhhppnphnphnhhpnhphnhn
output:
23
result:
ok single line: '23'
Test #60:
score: 0
Accepted
time: 2ms
memory: 3400kb
input:
ebbbebeeeeebzzbezzbbbzebzebzeezzeebzzeeebzebebbezezebbeezzzbzbbeezezbbezezbeeebbzebzzezezbbeebzezee
output:
17
result:
ok single line: '17'
Test #61:
score: 0
Accepted
time: 2ms
memory: 3352kb
input:
hhhttatththhaahthhhataaaahaaaahahhaahhtttahhaataaahthhataahaahhttahaththhhhhahaatthaahatahaahaahtha
output:
21
result:
ok single line: '21'
Test #62:
score: 0
Accepted
time: 0ms
memory: 3340kb
input:
ycccsysccsscycsysyyycsyssssscycyyccccycyycssssysscsycscssscscyyycyysycsysyyccscyyscccyycysycsycyycs
output:
20
result:
ok single line: '20'
Test #63:
score: 0
Accepted
time: 2ms
memory: 3388kb
input:
hhphpjhhhjhjphjjpjhpphhhpjppphpjpphjhpppjhhjpphjjphpppjppphppjhhphjpjphjhppjhpppjjjhjhjhjjjjhppphph
output:
23
result:
ok single line: '23'
Test #64:
score: 0
Accepted
time: 1ms
memory: 3328kb
input:
assjjsssajajssssssasjsasjsjjajasjjassaassasaajjssjjsasasaasjjjjasaajsssasaaaasjssjajaasajsajsjsjjja
output:
20
result:
ok single line: '20'
Test #65:
score: 0
Accepted
time: 2ms
memory: 3396kb
input:
cwwkwkcwwcwwckwwwkkcwkcckkkwwcwcwkkkckwkwcwkcckkwkwkkcckckwkwcckcwcwkcwckkckwkwkkcwkkcwwkcccckkwwkk
output:
19
result:
ok single line: '19'
Test #66:
score: 0
Accepted
time: 0ms
memory: 3344kb
input:
plpwplwplpwllppllppllwwpwwwllplwlwwlplwplppwlplwlppwplllwwplpwlwppllpllwllwlwppwlpppwwwwwlppwwplwlp
output:
22
result:
ok single line: '22'
Test #67:
score: 0
Accepted
time: 1ms
memory: 3312kb
input:
cchrrhrwwrrwhwrrcrhwchhhhwwhhwchhcwwrhrwhhwwcwhwrcwwrwrrhhwwrwhcwchcwhwrcwrcrhcrrcrwwcwcrccrccccrrr
output:
22
result:
ok single line: '22'
Test #68:
score: 0
Accepted
time: 2ms
memory: 3344kb
input:
hjjhhrjhhrgrghggrrjrrrrgrjhhjjrrggrjrgjghrrhjghjhrggrjjhrrgrhggrgjgjhjhhghhjrgrhjggggjjhjrhghrhhrhr
output:
19
result:
ok single line: '19'
Test #69:
score: 0
Accepted
time: 2ms
memory: 3280kb
input:
wfwnfnfwccwnfcfwwnfwnfwfcccfccwffnwcncncfcwwnwwccccnnfwccffcfncwfccfwnnnwnwncccfcwfffcnfwwwwwwnncnc
output:
22
result:
ok single line: '22'
Test #70:
score: 0
Accepted
time: 2ms
memory: 3316kb
input:
bgbbwxbxggggxxwwwbbwxxgwgxwgwbxbgbwwwwbgggxwbwxgwxwbxgxwxwbwgbxwxxwwbxbbwxwgwgwxxgxgxwbwxgwxbbwxgbw
output:
23
result:
ok single line: '23'
Test #71:
score: 0
Accepted
time: 2ms
memory: 3340kb
input:
zwzwzzcwczzzzwcwmmzmcczwmwzzzwcccczzwzzzczwcwmccwzmccmwwcccwzcwzcwzmwwzwcmwcccwccwczmmzwzmwcwcwmmcc
output:
22
result:
ok single line: '22'
Test #72:
score: 0
Accepted
time: 2ms
memory: 3408kb
input:
abbbybbaxabbxbyyxbxbxxxxyybbayaabxaxabxybxbybbaaxbyybyyaxybayxyxybxbxbyyaxaybbyyyayyxxbxbabybxabxyy
output:
22
result:
ok single line: '22'
Test #73:
score: 0
Accepted
time: 2ms
memory: 3400kb
input:
grzrzrrrzggggrgzkzrkzrggkgkkkrgzrzkzzgzkrkzkgkkrzzgkzzrzrgkkzkzkgzrkgrgkzgrzrzkgkzrgkrrrrkrrkrrkkzg
output:
24
result:
ok single line: '24'
Test #74:
score: 0
Accepted
time: 2ms
memory: 3284kb
input:
xxmxyxdmdyymmxmmxdmyyyxmdmxymxyymmyyymdymyydxymyxxyyddmdydyxxdmxxdyxdmdyxyddxdxydxddmmyxyydymmymddm
output:
21
result:
ok single line: '21'
Test #75:
score: 0
Accepted
time: 0ms
memory: 3324kb
input:
grgffrrgfrrrfbfgbbrfggbrbbbgfrbgrbgfgfgbgfbrrrrrbfbgbbbbfffbfrrrrfrrbbgfgffrfbggrrrfbrrgrgfrffrbrgr
output:
24
result:
ok single line: '24'
Test #76:
score: 0
Accepted
time: 2ms
memory: 3408kb
input:
wgfguufuufgwfugwwugffgwgffgufgfufugwffgwuwguwufuguwuwwfwuwfguguuugfggufgufuwufuwfwwwwgwgwgfgffuuguu
output:
23
result:
ok single line: '23'