QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#333528 | #5577. Alchemy | joelgun14# | AC ✓ | 0ms | 3840kb | C++14 | 1.6kb | 2024-02-20 05:54:32 | 2024-02-20 05:54:32 |
Judging History
answer
#include <bits/stdc++.h>
#define fi first
#define se second
#define bit(x) (1LL << (x))
#define getbit(x, i) (((x) >> (i)) & 1)
#define ALL(x) (x.begin(), x.end())
using namespace std;
template <typename T1, typename T2> bool maxi(T1 &a, T2 b) {
if (a < b) {a = b; return true;} return false;
}
template <typename T1, typename T2> bool mini(T1 &a, T2 b) {
if (a > b) {a = b; return true;} return false;
}
const int N = 2e5 + 5;
const int oo = 1e9;
const long long ooo = 1e18;
int main() {
string s;
cin >> s;
bool ans[s.size() / 2];
memset(ans, 0, sizeof(ans));
for(int i = 0; i < s.size() / 2; ++i) {
if(s[i] != s[s.size() - i - 1]) {
ans[i] = 1;
}
}
reverse(ans, ans + s.size() / 2);
// 0 -> wrong
// 1 -> correct
int dp[s.size() / 2][2];
memset(dp, -1, sizeof(dp));
if(ans[0]) {
// wrong
dp[0][1] = 1;
dp[0][0] = 0;
}
else {
// corect
dp[0][1] = 0;
dp[0][0] = 1;
}
for(int i = 1; i < s.size() / 2; ++i) {
// toggle prev wrong
dp[i][0] = dp[i - 1][0] + 1;
if(ans[i])
dp[i][1] = dp[i - 1][0] + 1;
else
dp[i][1] = 1e9;
// not toggle prev correct
if(ans[i]) {
// current wrong
dp[i][0] = min(dp[i][0], dp[i - 1][1]);
dp[i][1] = min(dp[i][1], dp[i - 1][1] + 2);
}
else {
dp[i][1] = min(dp[i][1], dp[i - 1][1]);
dp[i][0] = min(dp[i][0], dp[i - 1][1] + 2);
}
}
cout << dp[s.size() / 2 - 1][1] << endl;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3540kb
input:
ioi
output:
0
result:
ok single line: '0'
Test #2:
score: 0
Accepted
time: 0ms
memory: 3592kb
input:
noi
output:
1
result:
ok single line: '1'
Test #3:
score: 0
Accepted
time: 0ms
memory: 3828kb
input:
ctsc
output:
1
result:
ok single line: '1'
Test #4:
score: 0
Accepted
time: 0ms
memory: 3540kb
input:
fool
output:
2
result:
ok single line: '2'
Test #5:
score: 0
Accepted
time: 0ms
memory: 3832kb
input:
vetted
output:
2
result:
ok single line: '2'
Test #6:
score: 0
Accepted
time: 0ms
memory: 3608kb
input:
aa
output:
0
result:
ok single line: '0'
Test #7:
score: 0
Accepted
time: 0ms
memory: 3540kb
input:
ic
output:
1
result:
ok single line: '1'
Test #8:
score: 0
Accepted
time: 0ms
memory: 3600kb
input:
tlffohemdcncrfrxaqsbzcoyodvbxmhqukvfpahnakexcmacqa
output:
12
result:
ok single line: '12'
Test #9:
score: 0
Accepted
time: 0ms
memory: 3640kb
input:
qrgld
output:
1
result:
ok single line: '1'
Test #10:
score: 0
Accepted
time: 0ms
memory: 3764kb
input:
ejyfprguvwrnrsrykyrotmdjuzroohvlxqhvyeukkvmshtpczyyecpzhsqvkxueqvhlxldhofrzcjdhtotykgrsdnrnvuyrphyjy
output:
26
result:
ok single line: '26'
Test #11:
score: 0
Accepted
time: 0ms
memory: 3832kb
input:
xcpccpcy
output:
2
result:
ok single line: '2'
Test #12:
score: 0
Accepted
time: 0ms
memory: 3580kb
input:
abpccpcp
output:
1
result:
ok single line: '1'
Test #13:
score: 0
Accepted
time: 0ms
memory: 3796kb
input:
ixpccpci
output:
2
result:
ok single line: '2'
Test #14:
score: 0
Accepted
time: 0ms
memory: 3608kb
input:
xcxccpci
output:
2
result:
ok single line: '2'
Test #15:
score: 0
Accepted
time: 0ms
memory: 3600kb
input:
xcpxcpci
output:
3
result:
ok single line: '3'
Test #16:
score: 0
Accepted
time: 0ms
memory: 3604kb
input:
ixxccpci
output:
1
result:
ok single line: '1'
Test #17:
score: 0
Accepted
time: 0ms
memory: 3540kb
input:
ixpxcpci
output:
2
result:
ok single line: '2'
Test #18:
score: 0
Accepted
time: 0ms
memory: 3832kb
input:
ixpxxycpci
output:
3
result:
ok single line: '3'
Test #19:
score: 0
Accepted
time: 0ms
memory: 3640kb
input:
yxxxyxxxxxyyxxyxxyxyyyxyxyyyyxyxxxxxxxxxxxxyyxxyxyxyyxxyyxyxxyyxxyyyyyyxxyyxxyyxxxxyyyxxxyyxyxyxxyxx
output:
19
result:
ok single line: '19'
Test #20:
score: 0
Accepted
time: 0ms
memory: 3604kb
input:
caacbbacc
output:
2
result:
ok single line: '2'
Test #21:
score: 0
Accepted
time: 0ms
memory: 3600kb
input:
xjnfkxxjfnjx
output:
2
result:
ok single line: '2'
Test #22:
score: 0
Accepted
time: 0ms
memory: 3768kb
input:
baabaaa
output:
2
result:
ok single line: '2'
Test #23:
score: 0
Accepted
time: 0ms
memory: 3536kb
input:
bbaccaabcabca
output:
3
result:
ok single line: '3'
Test #24:
score: 0
Accepted
time: 0ms
memory: 3764kb
input:
ozo
output:
0
result:
ok single line: '0'
Test #25:
score: 0
Accepted
time: 0ms
memory: 3540kb
input:
zoooo
output:
2
result:
ok single line: '2'
Test #26:
score: 0
Accepted
time: 0ms
memory: 3596kb
input:
zooooo
output:
2
result:
ok single line: '2'
Test #27:
score: 0
Accepted
time: 0ms
memory: 3484kb
input:
ccclcclllclllcllcccccclclclclccccccllllllclccclcccllclclcllcllcllccllcllclccllclcclcclclllclllclclcc
output:
16
result:
ok single line: '16'
Test #28:
score: 0
Accepted
time: 0ms
memory: 3600kb
input:
hhzhhhhzzzzhzhzzzhhzzhzzzzhzzhhzhzhhzhhhzzhzzhzzzzhzzzzhzhzhzhzzhhhhzhzzhzhhhzzzhzzhhzzhzzzzhhhzhhzz
output:
22
result:
ok single line: '22'
Test #29:
score: 0
Accepted
time: 0ms
memory: 3536kb
input:
vaaaaaaavvavvaaaaavvavavavvvvvavavvvvvavvvvaavaavavvvvavavvvvavvavvvavvvvvvvavvvavaaavavvaaaavaavvaa
output:
18
result:
ok single line: '18'
Test #30:
score: 0
Accepted
time: 0ms
memory: 3828kb
input:
pjppjjpjpjjpjppjpppjpjjjjjppjjpjppjpjpppjjjppppjpjpjjjpjpjppjpppjjpppppjpjpjjpjjjppjjjpjjjjjpjpjjppj
output:
20
result:
ok single line: '20'
Test #31:
score: 0
Accepted
time: 0ms
memory: 3532kb
input:
xxxlllxllllxlxlxllxlxlxxlxxlxxllxlxxxlxlxllxxllxllxxlxxlxxlllxxxlxxlllxxxlllllxxxxxxxlxlllxxlxlxllll
output:
20
result:
ok single line: '20'
Test #32:
score: 0
Accepted
time: 0ms
memory: 3836kb
input:
gggggvgvgggggvggvggggvvgvgvvgvggvggvgvvgvgvvvvvgvggvvgvgvvvgvvgggvvgggvgggggvggggggvvvggvggggvvgvggg
output:
17
result:
ok single line: '17'
Test #33:
score: 0
Accepted
time: 0ms
memory: 3604kb
input:
vvvbbvvbbvvbbvbvbbbbbbvbvvvbvvbbvbbvvvbbbvbvbbvbvbbvbbvvvbvbbbvbvbbbbbvbbvvvbbbbbvbvvbvvbvbbbbvbbvbb
output:
18
result:
ok single line: '18'
Test #34:
score: 0
Accepted
time: 0ms
memory: 3540kb
input:
ooooeeeeoeoeeoooeeeeeeoooeoooooeeoeoooeeoeeeoeooeooeeeooeeeeoooeeeoooeeeoooooooeoeoeeoeeoooeeooeoooe
output:
20
result:
ok single line: '20'
Test #35:
score: 0
Accepted
time: 0ms
memory: 3540kb
input:
fvfvvffvvfffvfvfffvfvfffffvvvfvfffvffvffvvvfvffvffvffvvfvfffvfvvvfvfvfvfvfvfvffvfvffvffvfvvvfvfffvfv
output:
19
result:
ok single line: '19'
Test #36:
score: 0
Accepted
time: 0ms
memory: 3608kb
input:
vvvnvnnnvnvvvnvnvvvvvnvvnnvnnvnnvvvnvnnvvvnvvnvnnnvnnnnnvvvnnvnvnnvnnvvnnvnnvnvvvvnvvnnnnvvvnnvnnnvn
output:
20
result:
ok single line: '20'
Test #37:
score: 0
Accepted
time: 0ms
memory: 3608kb
input:
vxvexexxexxvvexxeexexvvvxexxxvxeevxeevvexvevxevexevxxvvevvevexexeeexxexvxexeexvxexvevxxxxxxxeevvexev
output:
22
result:
ok single line: '22'
Test #38:
score: 0
Accepted
time: 0ms
memory: 3636kb
input:
fssfkffsfsssffffsskfssssfkffkfksfkssfsffkkfffssksskfkskkkkkkfffffkkkfkkfffffkfsssskkssfksffffffffkff
output:
21
result:
ok single line: '21'
Test #39:
score: 0
Accepted
time: 0ms
memory: 3600kb
input:
effyeyyeeyeefefyeyfffeeeffffyfyefyeyyyfefeffyefyyefyyfyfffyyfyfefefyfyeffyffeyfeefffyyeeeyfyyeffeffy
output:
22
result:
ok single line: '22'
Test #40:
score: 0
Accepted
time: 0ms
memory: 3604kb
input:
attftftaatataftfaftfftffaaafatafattffatfffattatattttffttaffaftaftafffaffatttatatftaafattttffaffttfff
output:
21
result:
ok single line: '21'
Test #41:
score: 0
Accepted
time: 0ms
memory: 3588kb
input:
dxdttddxxtdxxddxxxtdxtdtddtddttxxddddxxdxddttxdxdtttddtdxttdtdxxttdxtxxxtxxdtxxdxtxdtdtxdxttdttxxxxd
output:
21
result:
ok single line: '21'
Test #42:
score: 0
Accepted
time: 0ms
memory: 3596kb
input:
etetetextttxetteexeetttteeetxeeeexxeeettexeteteeexetxtexxxexeeetexxxttxetttxetxetetxxxeexxteteexextt
output:
25
result:
ok single line: '25'
Test #43:
score: 0
Accepted
time: 0ms
memory: 3604kb
input:
cuccddddcuccduuduccdducdcudcdccducdcccccduucdducccuuucddcdccdudddcccddudcdcdududuccdudduduucdduddddu
output:
21
result:
ok single line: '21'
Test #44:
score: 0
Accepted
time: 0ms
memory: 3568kb
input:
eeleleeljljjellejjlejjleelljllllllleljljllelejjeeelllejjjjljeeejjleljlelleejjejeleeleeljejejjjejelee
output:
23
result:
ok single line: '23'
Test #45:
score: 0
Accepted
time: 0ms
memory: 3604kb
input:
kkkvkyvvkykkkkyyyvkyyvvyyvvykvkkvvvyvyyyvykkykyyvvkvvyyyykkkyvkykvyyyvkyvkkkkkkkvvvkvvyvvkkkkkyvvkvv
output:
23
result:
ok single line: '23'
Test #46:
score: 0
Accepted
time: 0ms
memory: 3808kb
input:
fddfftftfdfffdtttdfdffddtdffdtffftdfdffftddddffdddffddtddftfttdtfdtffdftttdtdfdfdddttffftdtfddtttfft
output:
19
result:
ok single line: '19'
Test #47:
score: 0
Accepted
time: 0ms
memory: 3604kb
input:
aoaoaoaaaoaaoaoaoaooaoaoaaooaoaaooaaoooaooaooaaoaooaaaaaoooooaaoaoaoaaaoooaaaooaaaaaaooooaaaaaaaaoo
output:
21
result:
ok single line: '21'
Test #48:
score: 0
Accepted
time: 0ms
memory: 3836kb
input:
yyyyydddyyddyyydddyddddyyyyyyddydydyddyddyydyddddyyddddyyddyyydyddyddddyydyyydddddyddyydddddyyyddyy
output:
20
result:
ok single line: '20'
Test #49:
score: 0
Accepted
time: 0ms
memory: 3664kb
input:
eaeeaaaaeaaeaaaaeeeeaeaeaaaeaeeeaeaaaaaeeaaaeaaeeaaaeeaeeeeaeaeaeaeeaeeaaeaeeaaeaeeaaaeeeeeaaeeaaaa
output:
22
result:
ok single line: '22'
Test #50:
score: 0
Accepted
time: 0ms
memory: 3576kb
input:
yeeyyyyeyyyeyyeeyyyeeyyeeeyyeeyyyeeeeeeyeeyyeeyyeeyyyyeyeeeeeyeyeyeyyeyyyeeeeeeyyeyyeyyyyyyeyyeyeye
output:
21
result:
ok single line: '21'
Test #51:
score: 0
Accepted
time: 0ms
memory: 3536kb
input:
mummmuumuummmuuumumuumummmumumuumuuuuumumuuuumummummmumuummuumummmumuuummmmuummumummuuuuummuumuuumu
output:
22
result:
ok single line: '22'
Test #52:
score: 0
Accepted
time: 0ms
memory: 3600kb
input:
cnnnncncncnccnncnncncccnnccnccnncccnnncccnccccnncnnnnncccnccccnnncccccnccncncncccccncnncnccncnccnnc
output:
18
result:
ok single line: '18'
Test #53:
score: 0
Accepted
time: 0ms
memory: 3836kb
input:
iiirriiirriiiriirrririrrriiririirriiriiriiiirrririrrrrrriirrriiiirriiiiiiiriiiirrririiriiiiirririrr
output:
17
result:
ok single line: '17'
Test #54:
score: 0
Accepted
time: 0ms
memory: 3604kb
input:
kkkkkkekeekkeekekkkeeekkkekeekeekkkeeeeekkekkeekekkekkkeeekeeekeeekkkkkkekkeekkekkekekkeeeekekekeek
output:
19
result:
ok single line: '19'
Test #55:
score: 0
Accepted
time: 0ms
memory: 3540kb
input:
gdddggdddggdddddgggddgdddgggdddgdgdggdgddgdddddgggggddddggggddddgddgdgddgddgggdgdgggddggdgdgddgdgdg
output:
19
result:
ok single line: '19'
Test #56:
score: 0
Accepted
time: 0ms
memory: 3604kb
input:
piipippppippiiiippiiipppiipppiiiiipiippiiiipiipipiiippppippipipippppipiipppippippppipiipippppiipipp
output:
18
result:
ok single line: '18'
Test #57:
score: 0
Accepted
time: 0ms
memory: 3544kb
input:
kfppkkfkpfkppffpppffkkfkpppfkpppppkkfffkkfppfffkfpppkppffpfpkffkkppppkpffpkpkpkkkfkpkfkkpkpkpfkpkpk
output:
19
result:
ok single line: '19'
Test #58:
score: 0
Accepted
time: 0ms
memory: 3540kb
input:
ggaaaamggmmgaagagaagmgggmamgggmmammmaaggggmaaaaggagmmmgmaaggagagmaaammmmammgagmgamgagaaamggaamgagga
output:
21
result:
ok single line: '21'
Test #59:
score: 0
Accepted
time: 0ms
memory: 3604kb
input:
phhnphhnphnphhnnpnhpppnnhnnpphnpnnhhhphnpnnhnpnpphphhhhpphnphnnpphpnhnhnhhhnphhhppnphnphnhhpnhphnhn
output:
23
result:
ok single line: '23'
Test #60:
score: 0
Accepted
time: 0ms
memory: 3604kb
input:
ebbbebeeeeebzzbezzbbbzebzebzeezzeebzzeeebzebebbezezebbeezzzbzbbeezezbbezezbeeebbzebzzezezbbeebzezee
output:
17
result:
ok single line: '17'
Test #61:
score: 0
Accepted
time: 0ms
memory: 3608kb
input:
hhhttatththhaahthhhataaaahaaaahahhaahhtttahhaataaahthhataahaahhttahaththhhhhahaatthaahatahaahaahtha
output:
21
result:
ok single line: '21'
Test #62:
score: 0
Accepted
time: 0ms
memory: 3548kb
input:
ycccsysccsscycsysyyycsyssssscycyyccccycyycssssysscsycscssscscyyycyysycsysyyccscyyscccyycysycsycyycs
output:
20
result:
ok single line: '20'
Test #63:
score: 0
Accepted
time: 0ms
memory: 3832kb
input:
hhphpjhhhjhjphjjpjhpphhhpjppphpjpphjhpppjhhjpphjjphpppjppphppjhhphjpjphjhppjhpppjjjhjhjhjjjjhppphph
output:
23
result:
ok single line: '23'
Test #64:
score: 0
Accepted
time: 0ms
memory: 3596kb
input:
assjjsssajajssssssasjsasjsjjajasjjassaassasaajjssjjsasasaasjjjjasaajsssasaaaasjssjajaasajsajsjsjjja
output:
20
result:
ok single line: '20'
Test #65:
score: 0
Accepted
time: 0ms
memory: 3484kb
input:
cwwkwkcwwcwwckwwwkkcwkcckkkwwcwcwkkkckwkwcwkcckkwkwkkcckckwkwcckcwcwkcwckkckwkwkkcwkkcwwkcccckkwwkk
output:
19
result:
ok single line: '19'
Test #66:
score: 0
Accepted
time: 0ms
memory: 3484kb
input:
plpwplwplpwllppllppllwwpwwwllplwlwwlplwplppwlplwlppwplllwwplpwlwppllpllwllwlwppwlpppwwwwwlppwwplwlp
output:
22
result:
ok single line: '22'
Test #67:
score: 0
Accepted
time: 0ms
memory: 3576kb
input:
cchrrhrwwrrwhwrrcrhwchhhhwwhhwchhcwwrhrwhhwwcwhwrcwwrwrrhhwwrwhcwchcwhwrcwrcrhcrrcrwwcwcrccrccccrrr
output:
22
result:
ok single line: '22'
Test #68:
score: 0
Accepted
time: 0ms
memory: 3840kb
input:
hjjhhrjhhrgrghggrrjrrrrgrjhhjjrrggrjrgjghrrhjghjhrggrjjhrrgrhggrgjgjhjhhghhjrgrhjggggjjhjrhghrhhrhr
output:
19
result:
ok single line: '19'
Test #69:
score: 0
Accepted
time: 0ms
memory: 3764kb
input:
wfwnfnfwccwnfcfwwnfwnfwfcccfccwffnwcncncfcwwnwwccccnnfwccffcfncwfccfwnnnwnwncccfcwfffcnfwwwwwwnncnc
output:
22
result:
ok single line: '22'
Test #70:
score: 0
Accepted
time: 0ms
memory: 3544kb
input:
bgbbwxbxggggxxwwwbbwxxgwgxwgwbxbgbwwwwbgggxwbwxgwxwbxgxwxwbwgbxwxxwwbxbbwxwgwgwxxgxgxwbwxgwxbbwxgbw
output:
23
result:
ok single line: '23'
Test #71:
score: 0
Accepted
time: 0ms
memory: 3824kb
input:
zwzwzzcwczzzzwcwmmzmcczwmwzzzwcccczzwzzzczwcwmccwzmccmwwcccwzcwzcwzmwwzwcmwcccwccwczmmzwzmwcwcwmmcc
output:
22
result:
ok single line: '22'
Test #72:
score: 0
Accepted
time: 0ms
memory: 3640kb
input:
abbbybbaxabbxbyyxbxbxxxxyybbayaabxaxabxybxbybbaaxbyybyyaxybayxyxybxbxbyyaxaybbyyyayyxxbxbabybxabxyy
output:
22
result:
ok single line: '22'
Test #73:
score: 0
Accepted
time: 0ms
memory: 3604kb
input:
grzrzrrrzggggrgzkzrkzrggkgkkkrgzrzkzzgzkrkzkgkkrzzgkzzrzrgkkzkzkgzrkgrgkzgrzrzkgkzrgkrrrrkrrkrrkkzg
output:
24
result:
ok single line: '24'
Test #74:
score: 0
Accepted
time: 0ms
memory: 3604kb
input:
xxmxyxdmdyymmxmmxdmyyyxmdmxymxyymmyyymdymyydxymyxxyyddmdydyxxdmxxdyxdmdyxyddxdxydxddmmyxyydymmymddm
output:
21
result:
ok single line: '21'
Test #75:
score: 0
Accepted
time: 0ms
memory: 3576kb
input:
grgffrrgfrrrfbfgbbrfggbrbbbgfrbgrbgfgfgbgfbrrrrrbfbgbbbbfffbfrrrrfrrbbgfgffrfbggrrrfbrrgrgfrffrbrgr
output:
24
result:
ok single line: '24'
Test #76:
score: 0
Accepted
time: 0ms
memory: 3796kb
input:
wgfguufuufgwfugwwugffgwgffgufgfufugwffgwuwguwufuguwuwwfwuwfguguuugfggufgufuwufuwfwwwwgwgwgfgffuuguu
output:
23
result:
ok single line: '23'