QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#95808#5577. Alchemy__#AC ✓4ms3584kbC++142.1kb2023-04-11 22:18:572023-04-11 22:19:10

Judging History

你现在查看的是最新测评结果

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-04-11 22:19:10]
  • 评测
  • 测评结果:AC
  • 用时:4ms
  • 内存:3584kb
  • [2023-04-11 22:18:57]
  • 提交

answer

#include<bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>

#define ll long long
#define endl '\n'
#define int ll
using namespace std;
using namespace __gnu_pbds;

template<typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
const int N = 2e5+7, P1 = 31, P2 = 37, mod= 1e9 + 7;

int mul(int a, int b) {
    return (1LL * a * b) % mod;
}

int add(int a, int b) {
    a = (a + mod) % mod;
    b = (b + mod) % mod;
    return (a + b) % mod;
}

int fp(int b, int p) {
    if (b == 1 or p == 0)
        return 1;

    int ret = fp(b, p >> 1);
    ret = mul(ret, ret);

    if (p & 1)
        ret = mul(ret, b);

    return ret;
}

ll modInv(ll n) {
    return fp(n, mod - 2);
}

ll fact[N], inv[N];

void pre() {
    fact[0] = inv[0] = 1;
    for (ll i = 1; i < N; i++)
        fact[i] = (fact[i - 1] * i) % mod, inv[i] = fp(fact[i], mod - 2);
}

ll nCr(ll n, ll r) {
    return ((fact[n] * inv[r]) % mod * inv[n - r]) % mod;
}

ll nPr(ll n, ll r) {
    return ((fact[n] * inv[n - r])) % mod;
}
string s;
int dp[105];
int solve(int idx)
{
    if ( idx == s.size()/2)
        return 0;
    if (~dp[idx])
        return dp[idx];

    dp[idx] = 10000;
    if ( s[idx] != s[s.size()-1-idx])
    {
        int ad =(( s.size()-1-idx -idx <= 2) ? 1 : 2);
        dp[idx] = min(dp[idx],ad+solve(idx+1));
    }
    else
    {
        dp[idx] = min(dp[idx] ,solve(idx+1));
        return dp[idx];
    }

    for (int i = idx+1; i < s.size()/2; ++i) {
        if (s[i] != s[s.size()-1-i])
            dp[idx] = min(dp[idx],i-idx + solve(i+1));
    }
    return dp[idx];
}
void doWork() {
   cin >> s;
    memset(dp,-1,sizeof dp);
   cout << solve(0) << endl;
}

signed main() {
    ios::sync_with_stdio(false);
    cout.tie(nullptr);
    cin.tie(nullptr);
//    freopen("bisector.in","r",stdin);
//    freopen("bisector.out","w",stdout);
    int t = 1;
    // cout << primes.size() << endl;
   // cin >> t;
    while (t--) {
        doWork();
    }
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 2ms
memory: 3412kb

input:

ioi

output:

0

result:

ok single line: '0'

Test #2:

score: 0
Accepted
time: 2ms
memory: 3532kb

input:

noi

output:

1

result:

ok single line: '1'

Test #3:

score: 0
Accepted
time: 2ms
memory: 3428kb

input:

ctsc

output:

1

result:

ok single line: '1'

Test #4:

score: 0
Accepted
time: 2ms
memory: 3520kb

input:

fool

output:

2

result:

ok single line: '2'

Test #5:

score: 0
Accepted
time: 2ms
memory: 3348kb

input:

vetted

output:

2

result:

ok single line: '2'

Test #6:

score: 0
Accepted
time: 2ms
memory: 3376kb

input:

aa

output:

0

result:

ok single line: '0'

Test #7:

score: 0
Accepted
time: 2ms
memory: 3528kb

input:

ic

output:

1

result:

ok single line: '1'

Test #8:

score: 0
Accepted
time: 2ms
memory: 3416kb

input:

tlffohemdcncrfrxaqsbzcoyodvbxmhqukvfpahnakexcmacqa

output:

12

result:

ok single line: '12'

Test #9:

score: 0
Accepted
time: 2ms
memory: 3352kb

input:

qrgld

output:

1

result:

ok single line: '1'

Test #10:

score: 0
Accepted
time: 2ms
memory: 3524kb

input:

ejyfprguvwrnrsrykyrotmdjuzroohvlxqhvyeukkvmshtpczyyecpzhsqvkxueqvhlxldhofrzcjdhtotykgrsdnrnvuyrphyjy

output:

26

result:

ok single line: '26'

Test #11:

score: 0
Accepted
time: 0ms
memory: 3416kb

input:

xcpccpcy

output:

2

result:

ok single line: '2'

Test #12:

score: 0
Accepted
time: 2ms
memory: 3580kb

input:

abpccpcp

output:

1

result:

ok single line: '1'

Test #13:

score: 0
Accepted
time: 2ms
memory: 3348kb

input:

ixpccpci

output:

2

result:

ok single line: '2'

Test #14:

score: 0
Accepted
time: 2ms
memory: 3348kb

input:

xcxccpci

output:

2

result:

ok single line: '2'

Test #15:

score: 0
Accepted
time: 2ms
memory: 3448kb

input:

xcpxcpci

output:

3

result:

ok single line: '3'

Test #16:

score: 0
Accepted
time: 2ms
memory: 3580kb

input:

ixxccpci

output:

1

result:

ok single line: '1'

Test #17:

score: 0
Accepted
time: 1ms
memory: 3424kb

input:

ixpxcpci

output:

2

result:

ok single line: '2'

Test #18:

score: 0
Accepted
time: 0ms
memory: 3404kb

input:

ixpxxycpci

output:

3

result:

ok single line: '3'

Test #19:

score: 0
Accepted
time: 2ms
memory: 3308kb

input:

yxxxyxxxxxyyxxyxxyxyyyxyxyyyyxyxxxxxxxxxxxxyyxxyxyxyyxxyyxyxxyyxxyyyyyyxxyyxxyyxxxxyyyxxxyyxyxyxxyxx

output:

19

result:

ok single line: '19'

Test #20:

score: 0
Accepted
time: 2ms
memory: 3532kb

input:

caacbbacc

output:

2

result:

ok single line: '2'

Test #21:

score: 0
Accepted
time: 2ms
memory: 3408kb

input:

xjnfkxxjfnjx

output:

2

result:

ok single line: '2'

Test #22:

score: 0
Accepted
time: 1ms
memory: 3428kb

input:

baabaaa

output:

2

result:

ok single line: '2'

Test #23:

score: 0
Accepted
time: 2ms
memory: 3524kb

input:

bbaccaabcabca

output:

3

result:

ok single line: '3'

Test #24:

score: 0
Accepted
time: 0ms
memory: 3400kb

input:

ozo

output:

0

result:

ok single line: '0'

Test #25:

score: 0
Accepted
time: 2ms
memory: 3568kb

input:

zoooo

output:

2

result:

ok single line: '2'

Test #26:

score: 0
Accepted
time: 2ms
memory: 3348kb

input:

zooooo

output:

2

result:

ok single line: '2'

Test #27:

score: 0
Accepted
time: 1ms
memory: 3400kb

input:

ccclcclllclllcllcccccclclclclccccccllllllclccclcccllclclcllcllcllccllcllclccllclcclcclclllclllclclcc

output:

16

result:

ok single line: '16'

Test #28:

score: 0
Accepted
time: 2ms
memory: 3428kb

input:

hhzhhhhzzzzhzhzzzhhzzhzzzzhzzhhzhzhhzhhhzzhzzhzzzzhzzzzhzhzhzhzzhhhhzhzzhzhhhzzzhzzhhzzhzzzzhhhzhhzz

output:

22

result:

ok single line: '22'

Test #29:

score: 0
Accepted
time: 0ms
memory: 3424kb

input:

vaaaaaaavvavvaaaaavvavavavvvvvavavvvvvavvvvaavaavavvvvavavvvvavvavvvavvvvvvvavvvavaaavavvaaaavaavvaa

output:

18

result:

ok single line: '18'

Test #30:

score: 0
Accepted
time: 1ms
memory: 3348kb

input:

pjppjjpjpjjpjppjpppjpjjjjjppjjpjppjpjpppjjjppppjpjpjjjpjpjppjpppjjpppppjpjpjjpjjjppjjjpjjjjjpjpjjppj

output:

20

result:

ok single line: '20'

Test #31:

score: 0
Accepted
time: 2ms
memory: 3404kb

input:

xxxlllxllllxlxlxllxlxlxxlxxlxxllxlxxxlxlxllxxllxllxxlxxlxxlllxxxlxxlllxxxlllllxxxxxxxlxlllxxlxlxllll

output:

20

result:

ok single line: '20'

Test #32:

score: 0
Accepted
time: 1ms
memory: 3416kb

input:

gggggvgvgggggvggvggggvvgvgvvgvggvggvgvvgvgvvvvvgvggvvgvgvvvgvvgggvvgggvgggggvggggggvvvggvggggvvgvggg

output:

17

result:

ok single line: '17'

Test #33:

score: 0
Accepted
time: 1ms
memory: 3308kb

input:

vvvbbvvbbvvbbvbvbbbbbbvbvvvbvvbbvbbvvvbbbvbvbbvbvbbvbbvvvbvbbbvbvbbbbbvbbvvvbbbbbvbvvbvvbvbbbbvbbvbb

output:

18

result:

ok single line: '18'

Test #34:

score: 0
Accepted
time: 2ms
memory: 3424kb

input:

ooooeeeeoeoeeoooeeeeeeoooeoooooeeoeoooeeoeeeoeooeooeeeooeeeeoooeeeoooeeeoooooooeoeoeeoeeoooeeooeoooe

output:

20

result:

ok single line: '20'

Test #35:

score: 0
Accepted
time: 2ms
memory: 3348kb

input:

fvfvvffvvfffvfvfffvfvfffffvvvfvfffvffvffvvvfvffvffvffvvfvfffvfvvvfvfvfvfvfvfvffvfvffvffvfvvvfvfffvfv

output:

19

result:

ok single line: '19'

Test #36:

score: 0
Accepted
time: 2ms
memory: 3428kb

input:

vvvnvnnnvnvvvnvnvvvvvnvvnnvnnvnnvvvnvnnvvvnvvnvnnnvnnnnnvvvnnvnvnnvnnvvnnvnnvnvvvvnvvnnnnvvvnnvnnnvn

output:

20

result:

ok single line: '20'

Test #37:

score: 0
Accepted
time: 1ms
memory: 3444kb

input:

vxvexexxexxvvexxeexexvvvxexxxvxeevxeevvexvevxevexevxxvvevvevexexeeexxexvxexeexvxexvevxxxxxxxeevvexev

output:

22

result:

ok single line: '22'

Test #38:

score: 0
Accepted
time: 4ms
memory: 3416kb

input:

fssfkffsfsssffffsskfssssfkffkfksfkssfsffkkfffssksskfkskkkkkkfffffkkkfkkfffffkfsssskkssfksffffffffkff

output:

21

result:

ok single line: '21'

Test #39:

score: 0
Accepted
time: 2ms
memory: 3532kb

input:

effyeyyeeyeefefyeyfffeeeffffyfyefyeyyyfefeffyefyyefyyfyfffyyfyfefefyfyeffyffeyfeefffyyeeeyfyyeffeffy

output:

22

result:

ok single line: '22'

Test #40:

score: 0
Accepted
time: 2ms
memory: 3580kb

input:

attftftaatataftfaftfftffaaafatafattffatfffattatattttffttaffaftaftafffaffatttatatftaafattttffaffttfff

output:

21

result:

ok single line: '21'

Test #41:

score: 0
Accepted
time: 0ms
memory: 3532kb

input:

dxdttddxxtdxxddxxxtdxtdtddtddttxxddddxxdxddttxdxdtttddtdxttdtdxxttdxtxxxtxxdtxxdxtxdtdtxdxttdttxxxxd

output:

21

result:

ok single line: '21'

Test #42:

score: 0
Accepted
time: 2ms
memory: 3396kb

input:

etetetextttxetteexeetttteeetxeeeexxeeettexeteteeexetxtexxxexeeetexxxttxetttxetxetetxxxeexxteteexextt

output:

25

result:

ok single line: '25'

Test #43:

score: 0
Accepted
time: 2ms
memory: 3420kb

input:

cuccddddcuccduuduccdducdcudcdccducdcccccduucdducccuuucddcdccdudddcccddudcdcdududuccdudduduucdduddddu

output:

21

result:

ok single line: '21'

Test #44:

score: 0
Accepted
time: 2ms
memory: 3416kb

input:

eeleleeljljjellejjlejjleelljllllllleljljllelejjeeelllejjjjljeeejjleljlelleejjejeleeleeljejejjjejelee

output:

23

result:

ok single line: '23'

Test #45:

score: 0
Accepted
time: 1ms
memory: 3420kb

input:

kkkvkyvvkykkkkyyyvkyyvvyyvvykvkkvvvyvyyyvykkykyyvvkvvyyyykkkyvkykvyyyvkyvkkkkkkkvvvkvvyvvkkkkkyvvkvv

output:

23

result:

ok single line: '23'

Test #46:

score: 0
Accepted
time: 2ms
memory: 3408kb

input:

fddfftftfdfffdtttdfdffddtdffdtffftdfdffftddddffdddffddtddftfttdtfdtffdftttdtdfdfdddttffftdtfddtttfft

output:

19

result:

ok single line: '19'

Test #47:

score: 0
Accepted
time: 2ms
memory: 3408kb

input:

aoaoaoaaaoaaoaoaoaooaoaoaaooaoaaooaaoooaooaooaaoaooaaaaaoooooaaoaoaoaaaoooaaaooaaaaaaooooaaaaaaaaoo

output:

21

result:

ok single line: '21'

Test #48:

score: 0
Accepted
time: 2ms
memory: 3532kb

input:

yyyyydddyyddyyydddyddddyyyyyyddydydyddyddyydyddddyyddddyyddyyydyddyddddyydyyydddddyddyydddddyyyddyy

output:

20

result:

ok single line: '20'

Test #49:

score: 0
Accepted
time: 2ms
memory: 3564kb

input:

eaeeaaaaeaaeaaaaeeeeaeaeaaaeaeeeaeaaaaaeeaaaeaaeeaaaeeaeeeeaeaeaeaeeaeeaaeaeeaaeaeeaaaeeeeeaaeeaaaa

output:

22

result:

ok single line: '22'

Test #50:

score: 0
Accepted
time: 0ms
memory: 3420kb

input:

yeeyyyyeyyyeyyeeyyyeeyyeeeyyeeyyyeeeeeeyeeyyeeyyeeyyyyeyeeeeeyeyeyeyyeyyyeeeeeeyyeyyeyyyyyyeyyeyeye

output:

21

result:

ok single line: '21'

Test #51:

score: 0
Accepted
time: 2ms
memory: 3404kb

input:

mummmuumuummmuuumumuumummmumumuumuuuuumumuuuumummummmumuummuumummmumuuummmmuummumummuuuuummuumuuumu

output:

22

result:

ok single line: '22'

Test #52:

score: 0
Accepted
time: 2ms
memory: 3424kb

input:

cnnnncncncnccnncnncncccnnccnccnncccnnncccnccccnncnnnnncccnccccnnncccccnccncncncccccncnncnccncnccnnc

output:

18

result:

ok single line: '18'

Test #53:

score: 0
Accepted
time: 2ms
memory: 3416kb

input:

iiirriiirriiiriirrririrrriiririirriiriiriiiirrririrrrrrriirrriiiirriiiiiiiriiiirrririiriiiiirririrr

output:

17

result:

ok single line: '17'

Test #54:

score: 0
Accepted
time: 2ms
memory: 3432kb

input:

kkkkkkekeekkeekekkkeeekkkekeekeekkkeeeeekkekkeekekkekkkeeekeeekeeekkkkkkekkeekkekkekekkeeeekekekeek

output:

19

result:

ok single line: '19'

Test #55:

score: 0
Accepted
time: 2ms
memory: 3408kb

input:

gdddggdddggdddddgggddgdddgggdddgdgdggdgddgdddddgggggddddggggddddgddgdgddgddgggdgdgggddggdgdgddgdgdg

output:

19

result:

ok single line: '19'

Test #56:

score: 0
Accepted
time: 2ms
memory: 3448kb

input:

piipippppippiiiippiiipppiipppiiiiipiippiiiipiipipiiippppippipipippppipiipppippippppipiipippppiipipp

output:

18

result:

ok single line: '18'

Test #57:

score: 0
Accepted
time: 2ms
memory: 3532kb

input:

kfppkkfkpfkppffpppffkkfkpppfkpppppkkfffkkfppfffkfpppkppffpfpkffkkppppkpffpkpkpkkkfkpkfkkpkpkpfkpkpk

output:

19

result:

ok single line: '19'

Test #58:

score: 0
Accepted
time: 1ms
memory: 3584kb

input:

ggaaaamggmmgaagagaagmgggmamgggmmammmaaggggmaaaaggagmmmgmaaggagagmaaammmmammgagmgamgagaaamggaamgagga

output:

21

result:

ok single line: '21'

Test #59:

score: 0
Accepted
time: 2ms
memory: 3528kb

input:

phhnphhnphnphhnnpnhpppnnhnnpphnpnnhhhphnpnnhnpnpphphhhhpphnphnnpphpnhnhnhhhnphhhppnphnphnhhpnhphnhn

output:

23

result:

ok single line: '23'

Test #60:

score: 0
Accepted
time: 1ms
memory: 3568kb

input:

ebbbebeeeeebzzbezzbbbzebzebzeezzeebzzeeebzebebbezezebbeezzzbzbbeezezbbezezbeeebbzebzzezezbbeebzezee

output:

17

result:

ok single line: '17'

Test #61:

score: 0
Accepted
time: 1ms
memory: 3516kb

input:

hhhttatththhaahthhhataaaahaaaahahhaahhtttahhaataaahthhataahaahhttahaththhhhhahaatthaahatahaahaahtha

output:

21

result:

ok single line: '21'

Test #62:

score: 0
Accepted
time: 2ms
memory: 3420kb

input:

ycccsysccsscycsysyyycsyssssscycyyccccycyycssssysscsycscssscscyyycyysycsysyyccscyyscccyycysycsycyycs

output:

20

result:

ok single line: '20'

Test #63:

score: 0
Accepted
time: 0ms
memory: 3412kb

input:

hhphpjhhhjhjphjjpjhpphhhpjppphpjpphjhpppjhhjpphjjphpppjppphppjhhphjpjphjhppjhpppjjjhjhjhjjjjhppphph

output:

23

result:

ok single line: '23'

Test #64:

score: 0
Accepted
time: 2ms
memory: 3448kb

input:

assjjsssajajssssssasjsasjsjjajasjjassaassasaajjssjjsasasaasjjjjasaajsssasaaaasjssjajaasajsajsjsjjja

output:

20

result:

ok single line: '20'

Test #65:

score: 0
Accepted
time: 2ms
memory: 3404kb

input:

cwwkwkcwwcwwckwwwkkcwkcckkkwwcwcwkkkckwkwcwkcckkwkwkkcckckwkwcckcwcwkcwckkckwkwkkcwkkcwwkcccckkwwkk

output:

19

result:

ok single line: '19'

Test #66:

score: 0
Accepted
time: 2ms
memory: 3408kb

input:

plpwplwplpwllppllppllwwpwwwllplwlwwlplwplppwlplwlppwplllwwplpwlwppllpllwllwlwppwlpppwwwwwlppwwplwlp

output:

22

result:

ok single line: '22'

Test #67:

score: 0
Accepted
time: 2ms
memory: 3444kb

input:

cchrrhrwwrrwhwrrcrhwchhhhwwhhwchhcwwrhrwhhwwcwhwrcwwrwrrhhwwrwhcwchcwhwrcwrcrhcrrcrwwcwcrccrccccrrr

output:

22

result:

ok single line: '22'

Test #68:

score: 0
Accepted
time: 2ms
memory: 3356kb

input:

hjjhhrjhhrgrghggrrjrrrrgrjhhjjrrggrjrgjghrrhjghjhrggrjjhrrgrhggrgjgjhjhhghhjrgrhjggggjjhjrhghrhhrhr

output:

19

result:

ok single line: '19'

Test #69:

score: 0
Accepted
time: 2ms
memory: 3344kb

input:

wfwnfnfwccwnfcfwwnfwnfwfcccfccwffnwcncncfcwwnwwccccnnfwccffcfncwfccfwnnnwnwncccfcwfffcnfwwwwwwnncnc

output:

22

result:

ok single line: '22'

Test #70:

score: 0
Accepted
time: 1ms
memory: 3300kb

input:

bgbbwxbxggggxxwwwbbwxxgwgxwgwbxbgbwwwwbgggxwbwxgwxwbxgxwxwbwgbxwxxwwbxbbwxwgwgwxxgxgxwbwxgwxbbwxgbw

output:

23

result:

ok single line: '23'

Test #71:

score: 0
Accepted
time: 0ms
memory: 3264kb

input:

zwzwzzcwczzzzwcwmmzmcczwmwzzzwcccczzwzzzczwcwmccwzmccmwwcccwzcwzcwzmwwzwcmwcccwccwczmmzwzmwcwcwmmcc

output:

22

result:

ok single line: '22'

Test #72:

score: 0
Accepted
time: 2ms
memory: 3524kb

input:

abbbybbaxabbxbyyxbxbxxxxyybbayaabxaxabxybxbybbaaxbyybyyaxybayxyxybxbxbyyaxaybbyyyayyxxbxbabybxabxyy

output:

22

result:

ok single line: '22'

Test #73:

score: 0
Accepted
time: 0ms
memory: 3404kb

input:

grzrzrrrzggggrgzkzrkzrggkgkkkrgzrzkzzgzkrkzkgkkrzzgkzzrzrgkkzkzkgzrkgrgkzgrzrzkgkzrgkrrrrkrrkrrkkzg

output:

24

result:

ok single line: '24'

Test #74:

score: 0
Accepted
time: 2ms
memory: 3532kb

input:

xxmxyxdmdyymmxmmxdmyyyxmdmxymxyymmyyymdymyydxymyxxyyddmdydyxxdmxxdyxdmdyxyddxdxydxddmmyxyydymmymddm

output:

21

result:

ok single line: '21'

Test #75:

score: 0
Accepted
time: 2ms
memory: 3352kb

input:

grgffrrgfrrrfbfgbbrfggbrbbbgfrbgrbgfgfgbgfbrrrrrbfbgbbbbfffbfrrrrfrrbbgfgffrfbggrrrfbrrgrgfrffrbrgr

output:

24

result:

ok single line: '24'

Test #76:

score: 0
Accepted
time: 2ms
memory: 3580kb

input:

wgfguufuufgwfugwwugffgwgffgufgfufugwffgwuwguwufuguwuwwfwuwfguguuugfggufgufuwufuwfwwwwgwgwgfgffuuguu

output:

23

result:

ok single line: '23'