QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#259526 | #5577. Alchemy | anton_h# | AC ✓ | 359ms | 8180kb | C++20 | 1.7kb | 2023-11-21 00:12:23 | 2023-11-21 00:12:24 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vl = vector<ll>;
#define sz(c) ll((c).size())
#define FOR(i, a, b) for(ll i=(a);i<(b);i++)
#define all(c) begin(c),end(c)
#define pb push_back
#define FORD(i, a, b) for(ll i=(b)-1;i>=(a);i--)
using vvl = vector<vl>;
using pll = pair<ll, ll>;
using vpll = vector<pll>;
#define xx first
#define yy second
#define TR(X) ({if(1) cerr << "TR: " << (#X) << " = " << (X) << endl;})
const ll oo = 0x3f3f3f3f3f3f3f3f;
ll conv(ll a1, ll a2, ll b1, ll b2) {
if (a1 != b1 && a2 != b2)
return 1;
if (a1 == b1 && a2 == b2)
return 0;
return 2;
}
ll convArr[27][27][27][27];
int main() {
cin.sync_with_stdio(0);
cin.tie(0);
ll n;
string a;
cin >> a;
n = sz(a);
vl s;
for (char &c: a) s.pb(c - 'a');
vector<vvl> dp(n / 2, vvl(26, vl(26, 1e9)));
dp[0][s[0]][s.back()] = 0;
FOR(c1, 0, 27)FOR(c2, 0, 27)FOR(c3, 0, 27)FOR(c4, 0, 27) convArr[c1][c2][c3][c4] = conv(c1, c2, c3, c4);
FOR(i, 1, n / 2) {
FOR(c1, 0, 26)
FOR(c2, 0, 26)
FOR(c3, 0, 26)
FOR(c4, 0, 26) {
ll val = oo;
for (ll x: vl{c1, c2, 26}) {
val = min(val, dp[i - 1][c1][c2] + convArr[c1][s[i]][x][c3] + convArr[c2] [s[n - i - 1]][x][c4]);
}
dp[i][c3][c4] = min(dp[i][c3][c4], val);
}
}
ll ans = oo;
FOR(c1, 0, 26) FOR(c2, 0, 26) {
ans = min(ans, dp[n / 2 - 1][c1][c2] + (c1 != c2));
if (ans == 0) {
TR(c1);
TR(c2);
}
}
cout << ans << endl;
}
詳細信息
Test #1:
score: 100
Accepted
time: 3ms
memory: 7788kb
input:
ioi
output:
0
result:
ok single line: '0'
Test #2:
score: 0
Accepted
time: 1ms
memory: 7720kb
input:
noi
output:
1
result:
ok single line: '1'
Test #3:
score: 0
Accepted
time: 9ms
memory: 7736kb
input:
ctsc
output:
1
result:
ok single line: '1'
Test #4:
score: 0
Accepted
time: 8ms
memory: 7672kb
input:
fool
output:
2
result:
ok single line: '2'
Test #5:
score: 0
Accepted
time: 15ms
memory: 7952kb
input:
vetted
output:
2
result:
ok single line: '2'
Test #6:
score: 0
Accepted
time: 0ms
memory: 7944kb
input:
aa
output:
0
result:
ok single line: '0'
Test #7:
score: 0
Accepted
time: 0ms
memory: 7784kb
input:
ic
output:
1
result:
ok single line: '1'
Test #8:
score: 0
Accepted
time: 163ms
memory: 7976kb
input:
tlffohemdcncrfrxaqsbzcoyodvbxmhqukvfpahnakexcmacqa
output:
12
result:
ok single line: '12'
Test #9:
score: 0
Accepted
time: 6ms
memory: 7788kb
input:
qrgld
output:
1
result:
ok single line: '1'
Test #10:
score: 0
Accepted
time: 327ms
memory: 7824kb
input:
ejyfprguvwrnrsrykyrotmdjuzroohvlxqhvyeukkvmshtpczyyecpzhsqvkxueqvhlxldhofrzcjdhtotykgrsdnrnvuyrphyjy
output:
26
result:
ok single line: '26'
Test #11:
score: 0
Accepted
time: 18ms
memory: 7808kb
input:
xcpccpcy
output:
2
result:
ok single line: '2'
Test #12:
score: 0
Accepted
time: 22ms
memory: 8044kb
input:
abpccpcp
output:
1
result:
ok single line: '1'
Test #13:
score: 0
Accepted
time: 22ms
memory: 8044kb
input:
ixpccpci
output:
2
result:
ok single line: '2'
Test #14:
score: 0
Accepted
time: 18ms
memory: 8032kb
input:
xcxccpci
output:
2
result:
ok single line: '2'
Test #15:
score: 0
Accepted
time: 22ms
memory: 7836kb
input:
xcpxcpci
output:
3
result:
ok single line: '3'
Test #16:
score: 0
Accepted
time: 22ms
memory: 7840kb
input:
ixxccpci
output:
1
result:
ok single line: '1'
Test #17:
score: 0
Accepted
time: 18ms
memory: 7736kb
input:
ixpxcpci
output:
2
result:
ok single line: '2'
Test #18:
score: 0
Accepted
time: 28ms
memory: 8036kb
input:
ixpxxycpci
output:
3
result:
ok single line: '3'
Test #19:
score: 0
Accepted
time: 331ms
memory: 7872kb
input:
yxxxyxxxxxyyxxyxxyxyyyxyxyyyyxyxxxxxxxxxxxxyyxxyxyxyyxxyyxyxxyyxxyyyyyyxxyyxxyyxxxxyyyxxxyyxyxyxxyxx
output:
19
result:
ok single line: '19'
Test #20:
score: 0
Accepted
time: 22ms
memory: 7740kb
input:
caacbbacc
output:
2
result:
ok single line: '2'
Test #21:
score: 0
Accepted
time: 36ms
memory: 7820kb
input:
xjnfkxxjfnjx
output:
2
result:
ok single line: '2'
Test #22:
score: 0
Accepted
time: 15ms
memory: 7800kb
input:
baabaaa
output:
2
result:
ok single line: '2'
Test #23:
score: 0
Accepted
time: 32ms
memory: 7816kb
input:
bbaccaabcabca
output:
3
result:
ok single line: '3'
Test #24:
score: 0
Accepted
time: 0ms
memory: 8016kb
input:
ozo
output:
0
result:
ok single line: '0'
Test #25:
score: 0
Accepted
time: 8ms
memory: 7772kb
input:
zoooo
output:
2
result:
ok single line: '2'
Test #26:
score: 0
Accepted
time: 11ms
memory: 7728kb
input:
zooooo
output:
2
result:
ok single line: '2'
Test #27:
score: 0
Accepted
time: 333ms
memory: 8180kb
input:
ccclcclllclllcllcccccclclclclccccccllllllclccclcccllclclcllcllcllccllcllclccllclcclcclclllclllclclcc
output:
16
result:
ok single line: '16'
Test #28:
score: 0
Accepted
time: 332ms
memory: 7944kb
input:
hhzhhhhzzzzhzhzzzhhzzhzzzzhzzhhzhzhhzhhhzzhzzhzzzzhzzzzhzhzhzhzzhhhhzhzzhzhhhzzzhzzhhzzhzzzzhhhzhhzz
output:
22
result:
ok single line: '22'
Test #29:
score: 0
Accepted
time: 329ms
memory: 7932kb
input:
vaaaaaaavvavvaaaaavvavavavvvvvavavvvvvavvvvaavaavavvvvavavvvvavvavvvavvvvvvvavvvavaaavavvaaaavaavvaa
output:
18
result:
ok single line: '18'
Test #30:
score: 0
Accepted
time: 332ms
memory: 8180kb
input:
pjppjjpjpjjpjppjpppjpjjjjjppjjpjppjpjpppjjjppppjpjpjjjpjpjppjpppjjpppppjpjpjjpjjjppjjjpjjjjjpjpjjppj
output:
20
result:
ok single line: '20'
Test #31:
score: 0
Accepted
time: 359ms
memory: 7952kb
input:
xxxlllxllllxlxlxllxlxlxxlxxlxxllxlxxxlxlxllxxllxllxxlxxlxxlllxxxlxxlllxxxlllllxxxxxxxlxlllxxlxlxllll
output:
20
result:
ok single line: '20'
Test #32:
score: 0
Accepted
time: 330ms
memory: 7816kb
input:
gggggvgvgggggvggvggggvvgvgvvgvggvggvgvvgvgvvvvvgvggvvgvgvvvgvvgggvvgggvgggggvggggggvvvggvggggvvgvggg
output:
17
result:
ok single line: '17'
Test #33:
score: 0
Accepted
time: 339ms
memory: 7880kb
input:
vvvbbvvbbvvbbvbvbbbbbbvbvvvbvvbbvbbvvvbbbvbvbbvbvbbvbbvvvbvbbbvbvbbbbbvbbvvvbbbbbvbvvbvvbvbbbbvbbvbb
output:
18
result:
ok single line: '18'
Test #34:
score: 0
Accepted
time: 327ms
memory: 7876kb
input:
ooooeeeeoeoeeoooeeeeeeoooeoooooeeoeoooeeoeeeoeooeooeeeooeeeeoooeeeoooeeeoooooooeoeoeeoeeoooeeooeoooe
output:
20
result:
ok single line: '20'
Test #35:
score: 0
Accepted
time: 326ms
memory: 7876kb
input:
fvfvvffvvfffvfvfffvfvfffffvvvfvfffvffvffvvvfvffvffvffvvfvfffvfvvvfvfvfvfvfvfvffvfvffvffvfvvvfvfffvfv
output:
19
result:
ok single line: '19'
Test #36:
score: 0
Accepted
time: 338ms
memory: 7936kb
input:
vvvnvnnnvnvvvnvnvvvvvnvvnnvnnvnnvvvnvnnvvvnvvnvnnnvnnnnnvvvnnvnvnnvnnvvnnvnnvnvvvvnvvnnnnvvvnnvnnnvn
output:
20
result:
ok single line: '20'
Test #37:
score: 0
Accepted
time: 328ms
memory: 8140kb
input:
vxvexexxexxvvexxeexexvvvxexxxvxeevxeevvexvevxevexevxxvvevvevexexeeexxexvxexeexvxexvevxxxxxxxeevvexev
output:
22
result:
ok single line: '22'
Test #38:
score: 0
Accepted
time: 328ms
memory: 7948kb
input:
fssfkffsfsssffffsskfssssfkffkfksfkssfsffkkfffssksskfkskkkkkkfffffkkkfkkfffffkfsssskkssfksffffffffkff
output:
21
result:
ok single line: '21'
Test #39:
score: 0
Accepted
time: 332ms
memory: 7936kb
input:
effyeyyeeyeefefyeyfffeeeffffyfyefyeyyyfefeffyefyyefyyfyfffyyfyfefefyfyeffyffeyfeefffyyeeeyfyyeffeffy
output:
22
result:
ok single line: '22'
Test #40:
score: 0
Accepted
time: 338ms
memory: 8136kb
input:
attftftaatataftfaftfftffaaafatafattffatfffattatattttffttaffaftaftafffaffatttatatftaafattttffaffttfff
output:
21
result:
ok single line: '21'
Test #41:
score: 0
Accepted
time: 327ms
memory: 8136kb
input:
dxdttddxxtdxxddxxxtdxtdtddtddttxxddddxxdxddttxdxdtttddtdxttdtdxxttdxtxxxtxxdtxxdxtxdtdtxdxttdttxxxxd
output:
21
result:
ok single line: '21'
Test #42:
score: 0
Accepted
time: 332ms
memory: 8168kb
input:
etetetextttxetteexeetttteeetxeeeexxeeettexeteteeexetxtexxxexeeetexxxttxetttxetxetetxxxeexxteteexextt
output:
25
result:
ok single line: '25'
Test #43:
score: 0
Accepted
time: 328ms
memory: 7908kb
input:
cuccddddcuccduuduccdducdcudcdccducdcccccduucdducccuuucddcdccdudddcccddudcdcdududuccdudduduucdduddddu
output:
21
result:
ok single line: '21'
Test #44:
score: 0
Accepted
time: 330ms
memory: 8104kb
input:
eeleleeljljjellejjlejjleelljllllllleljljllelejjeeelllejjjjljeeejjleljlelleejjejeleeleeljejejjjejelee
output:
23
result:
ok single line: '23'
Test #45:
score: 0
Accepted
time: 332ms
memory: 7944kb
input:
kkkvkyvvkykkkkyyyvkyyvvyyvvykvkkvvvyvyyyvykkykyyvvkvvyyyykkkyvkykvyyyvkyvkkkkkkkvvvkvvyvvkkkkkyvvkvv
output:
23
result:
ok single line: '23'
Test #46:
score: 0
Accepted
time: 332ms
memory: 7936kb
input:
fddfftftfdfffdtttdfdffddtdffdtffftdfdffftddddffdddffddtddftfttdtfdtffdftttdtdfdfdddttffftdtfddtttfft
output:
19
result:
ok single line: '19'
Test #47:
score: 0
Accepted
time: 319ms
memory: 8048kb
input:
aoaoaoaaaoaaoaoaoaooaoaoaaooaoaaooaaoooaooaooaaoaooaaaaaoooooaaoaoaoaaaoooaaaooaaaaaaooooaaaaaaaaoo
output:
21
result:
ok single line: '21'
Test #48:
score: 0
Accepted
time: 330ms
memory: 7980kb
input:
yyyyydddyyddyyydddyddddyyyyyyddydydyddyddyydyddddyyddddyyddyyydyddyddddyydyyydddddyddyydddddyyyddyy
output:
20
result:
ok single line: '20'
Test #49:
score: 0
Accepted
time: 335ms
memory: 7916kb
input:
eaeeaaaaeaaeaaaaeeeeaeaeaaaeaeeeaeaaaaaeeaaaeaaeeaaaeeaeeeeaeaeaeaeeaeeaaeaeeaaeaeeaaaeeeeeaaeeaaaa
output:
22
result:
ok single line: '22'
Test #50:
score: 0
Accepted
time: 324ms
memory: 7948kb
input:
yeeyyyyeyyyeyyeeyyyeeyyeeeyyeeyyyeeeeeeyeeyyeeyyeeyyyyeyeeeeeyeyeyeyyeyyyeeeeeeyyeyyeyyyyyyeyyeyeye
output:
21
result:
ok single line: '21'
Test #51:
score: 0
Accepted
time: 320ms
memory: 7880kb
input:
mummmuumuummmuuumumuumummmumumuumuuuuumumuuuumummummmumuummuumummmumuuummmmuummumummuuuuummuumuuumu
output:
22
result:
ok single line: '22'
Test #52:
score: 0
Accepted
time: 317ms
memory: 7884kb
input:
cnnnncncncnccnncnncncccnnccnccnncccnnncccnccccnncnnnnncccnccccnnncccccnccncncncccccncnncnccncnccnnc
output:
18
result:
ok single line: '18'
Test #53:
score: 0
Accepted
time: 322ms
memory: 8176kb
input:
iiirriiirriiiriirrririrrriiririirriiriiriiiirrririrrrrrriirrriiiirriiiiiiiriiiirrririiriiiiirririrr
output:
17
result:
ok single line: '17'
Test #54:
score: 0
Accepted
time: 325ms
memory: 7976kb
input:
kkkkkkekeekkeekekkkeeekkkekeekeekkkeeeeekkekkeekekkekkkeeekeeekeeekkkkkkekkeekkekkekekkeeeekekekeek
output:
19
result:
ok single line: '19'
Test #55:
score: 0
Accepted
time: 326ms
memory: 7820kb
input:
gdddggdddggdddddgggddgdddgggdddgdgdggdgddgdddddgggggddddggggddddgddgdgddgddgggdgdgggddggdgdgddgdgdg
output:
19
result:
ok single line: '19'
Test #56:
score: 0
Accepted
time: 322ms
memory: 7836kb
input:
piipippppippiiiippiiipppiipppiiiiipiippiiiipiipipiiippppippipipippppipiipppippippppipiipippppiipipp
output:
18
result:
ok single line: '18'
Test #57:
score: 0
Accepted
time: 318ms
memory: 7948kb
input:
kfppkkfkpfkppffpppffkkfkpppfkpppppkkfffkkfppfffkfpppkppffpfpkffkkppppkpffpkpkpkkkfkpkfkkpkpkpfkpkpk
output:
19
result:
ok single line: '19'
Test #58:
score: 0
Accepted
time: 325ms
memory: 7944kb
input:
ggaaaamggmmgaagagaagmgggmamgggmmammmaaggggmaaaaggagmmmgmaaggagagmaaammmmammgagmgamgagaaamggaamgagga
output:
21
result:
ok single line: '21'
Test #59:
score: 0
Accepted
time: 320ms
memory: 7940kb
input:
phhnphhnphnphhnnpnhpppnnhnnpphnpnnhhhphnpnnhnpnpphphhhhpphnphnnpphpnhnhnhhhnphhhppnphnphnhhpnhphnhn
output:
23
result:
ok single line: '23'
Test #60:
score: 0
Accepted
time: 319ms
memory: 8096kb
input:
ebbbebeeeeebzzbezzbbbzebzebzeezzeebzzeeebzebebbezezebbeezzzbzbbeezezbbezezbeeebbzebzzezezbbeebzezee
output:
17
result:
ok single line: '17'
Test #61:
score: 0
Accepted
time: 323ms
memory: 7876kb
input:
hhhttatththhaahthhhataaaahaaaahahhaahhtttahhaataaahthhataahaahhttahaththhhhhahaatthaahatahaahaahtha
output:
21
result:
ok single line: '21'
Test #62:
score: 0
Accepted
time: 322ms
memory: 7952kb
input:
ycccsysccsscycsysyyycsyssssscycyyccccycyycssssysscsycscssscscyyycyysycsysyyccscyyscccyycysycsycyycs
output:
20
result:
ok single line: '20'
Test #63:
score: 0
Accepted
time: 321ms
memory: 8096kb
input:
hhphpjhhhjhjphjjpjhpphhhpjppphpjpphjhpppjhhjpphjjphpppjppphppjhhphjpjphjhppjhpppjjjhjhjhjjjjhppphph
output:
23
result:
ok single line: '23'
Test #64:
score: 0
Accepted
time: 321ms
memory: 7908kb
input:
assjjsssajajssssssasjsasjsjjajasjjassaassasaajjssjjsasasaasjjjjasaajsssasaaaasjssjajaasajsajsjsjjja
output:
20
result:
ok single line: '20'
Test #65:
score: 0
Accepted
time: 318ms
memory: 7872kb
input:
cwwkwkcwwcwwckwwwkkcwkcckkkwwcwcwkkkckwkwcwkcckkwkwkkcckckwkwcckcwcwkcwckkckwkwkkcwkkcwwkcccckkwwkk
output:
19
result:
ok single line: '19'
Test #66:
score: 0
Accepted
time: 323ms
memory: 7936kb
input:
plpwplwplpwllppllppllwwpwwwllplwlwwlplwplppwlplwlppwplllwwplpwlwppllpllwllwlwppwlpppwwwwwlppwwplwlp
output:
22
result:
ok single line: '22'
Test #67:
score: 0
Accepted
time: 325ms
memory: 7872kb
input:
cchrrhrwwrrwhwrrcrhwchhhhwwhhwchhcwwrhrwhhwwcwhwrcwwrwrrhhwwrwhcwchcwhwrcwrcrhcrrcrwwcwcrccrccccrrr
output:
22
result:
ok single line: '22'
Test #68:
score: 0
Accepted
time: 320ms
memory: 7876kb
input:
hjjhhrjhhrgrghggrrjrrrrgrjhhjjrrggrjrgjghrrhjghjhrggrjjhrrgrhggrgjgjhjhhghhjrgrhjggggjjhjrhghrhhrhr
output:
19
result:
ok single line: '19'
Test #69:
score: 0
Accepted
time: 323ms
memory: 7884kb
input:
wfwnfnfwccwnfcfwwnfwnfwfcccfccwffnwcncncfcwwnwwccccnnfwccffcfncwfccfwnnnwnwncccfcwfffcnfwwwwwwnncnc
output:
22
result:
ok single line: '22'
Test #70:
score: 0
Accepted
time: 325ms
memory: 7908kb
input:
bgbbwxbxggggxxwwwbbwxxgwgxwgwbxbgbwwwwbgggxwbwxgwxwbxgxwxwbwgbxwxxwwbxbbwxwgwgwxxgxgxwbwxgwxbbwxgbw
output:
23
result:
ok single line: '23'
Test #71:
score: 0
Accepted
time: 325ms
memory: 8180kb
input:
zwzwzzcwczzzzwcwmmzmcczwmwzzzwcccczzwzzzczwcwmccwzmccmwwcccwzcwzcwzmwwzwcmwcccwccwczmmzwzmwcwcwmmcc
output:
22
result:
ok single line: '22'
Test #72:
score: 0
Accepted
time: 323ms
memory: 8100kb
input:
abbbybbaxabbxbyyxbxbxxxxyybbayaabxaxabxybxbybbaaxbyybyyaxybayxyxybxbxbyyaxaybbyyyayyxxbxbabybxabxyy
output:
22
result:
ok single line: '22'
Test #73:
score: 0
Accepted
time: 338ms
memory: 7880kb
input:
grzrzrrrzggggrgzkzrkzrggkgkkkrgzrzkzzgzkrkzkgkkrzzgkzzrzrgkkzkzkgzrkgrgkzgrzrzkgkzrgkrrrrkrrkrrkkzg
output:
24
result:
ok single line: '24'
Test #74:
score: 0
Accepted
time: 323ms
memory: 7940kb
input:
xxmxyxdmdyymmxmmxdmyyyxmdmxymxyymmyyymdymyydxymyxxyyddmdydyxxdmxxdyxdmdyxyddxdxydxddmmyxyydymmymddm
output:
21
result:
ok single line: '21'
Test #75:
score: 0
Accepted
time: 330ms
memory: 7908kb
input:
grgffrrgfrrrfbfgbbrfggbrbbbgfrbgrbgfgfgbgfbrrrrrbfbgbbbbfffbfrrrrfrrbbgfgffrfbggrrrfbrrgrgfrffrbrgr
output:
24
result:
ok single line: '24'
Test #76:
score: 0
Accepted
time: 317ms
memory: 7932kb
input:
wgfguufuufgwfugwwugffgwgffgufgfufugwffgwuwguwufuguwuwwfwuwfguguuugfggufgufuwufuwfwwwwgwgwgfgffuuguu
output:
23
result:
ok single line: '23'