QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#101989#5577. AlchemyjoesmittyAC ✓2ms3528kbC++203.3kb2023-05-02 07:09:302023-05-02 07:09:32

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-05-02 07:09:32]
  • 评测
  • 测评结果:AC
  • 用时:2ms
  • 内存:3528kb
  • [2023-05-02 07:09:30]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef unsigned int uint;
typedef vector<int> vi;
typedef vector< vector <int> > vvi;
typedef pair<int, int> pii;
typedef pair < pair < int, int >, int > piii;
typedef pair < pair <int, int > , pair <int, int> > piiii;
typedef pair<ll, ll> pll;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<string> vs;
 
#define FOR(i,a,b) for(int i = a; i < b; i ++)
#define RFOR(i,a,b) for(int i = a-1; i >= b; i --)
#define all(a) a.begin(), a.end()
#define endl '\n';
#define sz(x) (int)(x).size()
 
#define mp make_pair
#define pb push_back
#define ff first
#define ss second
 
template <typename T>
void pr(vector<T> &v) {
    FOR(i, 0, sz(v)) cout << v[i] << " ";
    cout << endl;
}
template <typename T>
void pr(vector<vector<T> > &v) {
    FOR(i, 0, sz(v)) { pr(v[i]); }
}
template <typename T>
void re(T &x) {
    cin >> x;
}
template <typename T>
void re(vector<T> &a) {
    FOR(i, 0, sz(a)) re(a[i]);
}
template <class Arg, class... Args>
void re(Arg &first, Args &... rest) {
    re(first);
    re(rest...);
}
template <typename T>
void pr(T x) {
    cout << x << endl;
}
template <class Arg, class... Args>
void pr(const Arg &first, const Args &... rest) {
    cout << first << " ";
    pr(rest...);
    cout << endl;
}
void ps() { cout << endl; }
template<class T, class... Ts>
void ps(const T& t, const Ts&... ts) {
    cout << t; if (sizeof...(ts)) cout << " "; ps(ts...);
}
 
const ll MOD  =  998244353;
#define inf 1e18;
#define INF INT_MAX

long double PI = 4*atan(1);
long double eps = 1e-12;

int dp[100][2] = {};
int n;
string s;

int recurse(int idx, int diff) {
    if(dp[idx][diff] != -1) return dp[idx][diff];

    if(idx == (n-2)/2) {
        dp[idx][diff] = diff;
        return diff;
    }

    if(diff == 0) {
        int ndiff = (s[idx + 1] != s[n-2-idx]);
        int v1 = recurse(idx + 1, ndiff);
        int v2 = 1e9;
        int v3 = 1e9;
        if(ndiff) {
            v2 = 2 + recurse(idx + 1, 0);
            v3 = 2 + recurse(idx + 1, 1);
        }
        dp[idx][diff] = min({v1, v2, v3});
    } else {
        int ndiff = (s[idx + 1] != s[n-2-idx]);
        int v1 = 1e9;
        int v2 = 1e9;
        if(ndiff) {
            v1 = 1 + recurse(idx + 1, 0);
            v2 = 1 + recurse(idx + 1, 1);
        } else {
            v1 = 1 + recurse(idx + 1, 1);
            v2 = 2 + recurse(idx + 1, 0);
        }
        dp[idx][diff] = min(v1, v2);
    }
    return dp[idx][diff];
}


int main() {
    //auto start = chrono::high_resolution_clock::now();
    ios_base::sync_with_stdio(0);cin.tie(0);
    // ofstream cout("disrupt.out");
    // ifstream cin("disrupt.in");
    #ifdef DEBUG
      freopen("input.txt", "r", stdin);
      freopen("output.txt", "w", stdout);
    #endif 
    
     cin >> s;
    n = s.length();
    FOR(i,0,100) FOR(j,0,2) dp[i][j] = -1;



    int diff = (s[0] != s[n-1]);


    recurse(0, diff);

    cout << dp[0][diff] << endl;



    

    // auto stop = chrono::high_resolution_clock::now();
    // auto duration = chrono::duration_cast<chrono::microseconds>(stop - start);
    // cout << duration.count() << endl;
    //cin.close();
    //cout.close();
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3500kb

input:

ioi

output:

0

result:

ok single line: '0'

Test #2:

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

input:

noi

output:

1

result:

ok single line: '1'

Test #3:

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

input:

ctsc

output:

1

result:

ok single line: '1'

Test #4:

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

input:

fool

output:

2

result:

ok single line: '2'

Test #5:

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

input:

vetted

output:

2

result:

ok single line: '2'

Test #6:

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

input:

aa

output:

0

result:

ok single line: '0'

Test #7:

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

input:

ic

output:

1

result:

ok single line: '1'

Test #8:

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

input:

tlffohemdcncrfrxaqsbzcoyodvbxmhqukvfpahnakexcmacqa

output:

12

result:

ok single line: '12'

Test #9:

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

input:

qrgld

output:

1

result:

ok single line: '1'

Test #10:

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

input:

ejyfprguvwrnrsrykyrotmdjuzroohvlxqhvyeukkvmshtpczyyecpzhsqvkxueqvhlxldhofrzcjdhtotykgrsdnrnvuyrphyjy

output:

26

result:

ok single line: '26'

Test #11:

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

input:

xcpccpcy

output:

2

result:

ok single line: '2'

Test #12:

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

input:

abpccpcp

output:

1

result:

ok single line: '1'

Test #13:

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

input:

ixpccpci

output:

2

result:

ok single line: '2'

Test #14:

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

input:

xcxccpci

output:

2

result:

ok single line: '2'

Test #15:

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

input:

xcpxcpci

output:

3

result:

ok single line: '3'

Test #16:

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

input:

ixxccpci

output:

1

result:

ok single line: '1'

Test #17:

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

input:

ixpxcpci

output:

2

result:

ok single line: '2'

Test #18:

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

input:

ixpxxycpci

output:

3

result:

ok single line: '3'

Test #19:

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

input:

yxxxyxxxxxyyxxyxxyxyyyxyxyyyyxyxxxxxxxxxxxxyyxxyxyxyyxxyyxyxxyyxxyyyyyyxxyyxxyyxxxxyyyxxxyyxyxyxxyxx

output:

19

result:

ok single line: '19'

Test #20:

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

input:

caacbbacc

output:

2

result:

ok single line: '2'

Test #21:

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

input:

xjnfkxxjfnjx

output:

2

result:

ok single line: '2'

Test #22:

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

input:

baabaaa

output:

2

result:

ok single line: '2'

Test #23:

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

input:

bbaccaabcabca

output:

3

result:

ok single line: '3'

Test #24:

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

input:

ozo

output:

0

result:

ok single line: '0'

Test #25:

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

input:

zoooo

output:

2

result:

ok single line: '2'

Test #26:

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

input:

zooooo

output:

2

result:

ok single line: '2'

Test #27:

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

input:

ccclcclllclllcllcccccclclclclccccccllllllclccclcccllclclcllcllcllccllcllclccllclcclcclclllclllclclcc

output:

16

result:

ok single line: '16'

Test #28:

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

input:

hhzhhhhzzzzhzhzzzhhzzhzzzzhzzhhzhzhhzhhhzzhzzhzzzzhzzzzhzhzhzhzzhhhhzhzzhzhhhzzzhzzhhzzhzzzzhhhzhhzz

output:

22

result:

ok single line: '22'

Test #29:

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

input:

vaaaaaaavvavvaaaaavvavavavvvvvavavvvvvavvvvaavaavavvvvavavvvvavvavvvavvvvvvvavvvavaaavavvaaaavaavvaa

output:

18

result:

ok single line: '18'

Test #30:

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

input:

pjppjjpjpjjpjppjpppjpjjjjjppjjpjppjpjpppjjjppppjpjpjjjpjpjppjpppjjpppppjpjpjjpjjjppjjjpjjjjjpjpjjppj

output:

20

result:

ok single line: '20'

Test #31:

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

input:

xxxlllxllllxlxlxllxlxlxxlxxlxxllxlxxxlxlxllxxllxllxxlxxlxxlllxxxlxxlllxxxlllllxxxxxxxlxlllxxlxlxllll

output:

20

result:

ok single line: '20'

Test #32:

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

input:

gggggvgvgggggvggvggggvvgvgvvgvggvggvgvvgvgvvvvvgvggvvgvgvvvgvvgggvvgggvgggggvggggggvvvggvggggvvgvggg

output:

17

result:

ok single line: '17'

Test #33:

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

input:

vvvbbvvbbvvbbvbvbbbbbbvbvvvbvvbbvbbvvvbbbvbvbbvbvbbvbbvvvbvbbbvbvbbbbbvbbvvvbbbbbvbvvbvvbvbbbbvbbvbb

output:

18

result:

ok single line: '18'

Test #34:

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

input:

ooooeeeeoeoeeoooeeeeeeoooeoooooeeoeoooeeoeeeoeooeooeeeooeeeeoooeeeoooeeeoooooooeoeoeeoeeoooeeooeoooe

output:

20

result:

ok single line: '20'

Test #35:

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

input:

fvfvvffvvfffvfvfffvfvfffffvvvfvfffvffvffvvvfvffvffvffvvfvfffvfvvvfvfvfvfvfvfvffvfvffvffvfvvvfvfffvfv

output:

19

result:

ok single line: '19'

Test #36:

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

input:

vvvnvnnnvnvvvnvnvvvvvnvvnnvnnvnnvvvnvnnvvvnvvnvnnnvnnnnnvvvnnvnvnnvnnvvnnvnnvnvvvvnvvnnnnvvvnnvnnnvn

output:

20

result:

ok single line: '20'

Test #37:

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

input:

vxvexexxexxvvexxeexexvvvxexxxvxeevxeevvexvevxevexevxxvvevvevexexeeexxexvxexeexvxexvevxxxxxxxeevvexev

output:

22

result:

ok single line: '22'

Test #38:

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

input:

fssfkffsfsssffffsskfssssfkffkfksfkssfsffkkfffssksskfkskkkkkkfffffkkkfkkfffffkfsssskkssfksffffffffkff

output:

21

result:

ok single line: '21'

Test #39:

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

input:

effyeyyeeyeefefyeyfffeeeffffyfyefyeyyyfefeffyefyyefyyfyfffyyfyfefefyfyeffyffeyfeefffyyeeeyfyyeffeffy

output:

22

result:

ok single line: '22'

Test #40:

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

input:

attftftaatataftfaftfftffaaafatafattffatfffattatattttffttaffaftaftafffaffatttatatftaafattttffaffttfff

output:

21

result:

ok single line: '21'

Test #41:

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

input:

dxdttddxxtdxxddxxxtdxtdtddtddttxxddddxxdxddttxdxdtttddtdxttdtdxxttdxtxxxtxxdtxxdxtxdtdtxdxttdttxxxxd

output:

21

result:

ok single line: '21'

Test #42:

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

input:

etetetextttxetteexeetttteeetxeeeexxeeettexeteteeexetxtexxxexeeetexxxttxetttxetxetetxxxeexxteteexextt

output:

25

result:

ok single line: '25'

Test #43:

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

input:

cuccddddcuccduuduccdducdcudcdccducdcccccduucdducccuuucddcdccdudddcccddudcdcdududuccdudduduucdduddddu

output:

21

result:

ok single line: '21'

Test #44:

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

input:

eeleleeljljjellejjlejjleelljllllllleljljllelejjeeelllejjjjljeeejjleljlelleejjejeleeleeljejejjjejelee

output:

23

result:

ok single line: '23'

Test #45:

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

input:

kkkvkyvvkykkkkyyyvkyyvvyyvvykvkkvvvyvyyyvykkykyyvvkvvyyyykkkyvkykvyyyvkyvkkkkkkkvvvkvvyvvkkkkkyvvkvv

output:

23

result:

ok single line: '23'

Test #46:

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

input:

fddfftftfdfffdtttdfdffddtdffdtffftdfdffftddddffdddffddtddftfttdtfdtffdftttdtdfdfdddttffftdtfddtttfft

output:

19

result:

ok single line: '19'

Test #47:

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

input:

aoaoaoaaaoaaoaoaoaooaoaoaaooaoaaooaaoooaooaooaaoaooaaaaaoooooaaoaoaoaaaoooaaaooaaaaaaooooaaaaaaaaoo

output:

21

result:

ok single line: '21'

Test #48:

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

input:

yyyyydddyyddyyydddyddddyyyyyyddydydyddyddyydyddddyyddddyyddyyydyddyddddyydyyydddddyddyydddddyyyddyy

output:

20

result:

ok single line: '20'

Test #49:

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

input:

eaeeaaaaeaaeaaaaeeeeaeaeaaaeaeeeaeaaaaaeeaaaeaaeeaaaeeaeeeeaeaeaeaeeaeeaaeaeeaaeaeeaaaeeeeeaaeeaaaa

output:

22

result:

ok single line: '22'

Test #50:

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

input:

yeeyyyyeyyyeyyeeyyyeeyyeeeyyeeyyyeeeeeeyeeyyeeyyeeyyyyeyeeeeeyeyeyeyyeyyyeeeeeeyyeyyeyyyyyyeyyeyeye

output:

21

result:

ok single line: '21'

Test #51:

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

input:

mummmuumuummmuuumumuumummmumumuumuuuuumumuuuumummummmumuummuumummmumuuummmmuummumummuuuuummuumuuumu

output:

22

result:

ok single line: '22'

Test #52:

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

input:

cnnnncncncnccnncnncncccnnccnccnncccnnncccnccccnncnnnnncccnccccnnncccccnccncncncccccncnncnccncnccnnc

output:

18

result:

ok single line: '18'

Test #53:

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

input:

iiirriiirriiiriirrririrrriiririirriiriiriiiirrririrrrrrriirrriiiirriiiiiiiriiiirrririiriiiiirririrr

output:

17

result:

ok single line: '17'

Test #54:

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

input:

kkkkkkekeekkeekekkkeeekkkekeekeekkkeeeeekkekkeekekkekkkeeekeeekeeekkkkkkekkeekkekkekekkeeeekekekeek

output:

19

result:

ok single line: '19'

Test #55:

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

input:

gdddggdddggdddddgggddgdddgggdddgdgdggdgddgdddddgggggddddggggddddgddgdgddgddgggdgdgggddggdgdgddgdgdg

output:

19

result:

ok single line: '19'

Test #56:

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

input:

piipippppippiiiippiiipppiipppiiiiipiippiiiipiipipiiippppippipipippppipiipppippippppipiipippppiipipp

output:

18

result:

ok single line: '18'

Test #57:

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

input:

kfppkkfkpfkppffpppffkkfkpppfkpppppkkfffkkfppfffkfpppkppffpfpkffkkppppkpffpkpkpkkkfkpkfkkpkpkpfkpkpk

output:

19

result:

ok single line: '19'

Test #58:

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

input:

ggaaaamggmmgaagagaagmgggmamgggmmammmaaggggmaaaaggagmmmgmaaggagagmaaammmmammgagmgamgagaaamggaamgagga

output:

21

result:

ok single line: '21'

Test #59:

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

input:

phhnphhnphnphhnnpnhpppnnhnnpphnpnnhhhphnpnnhnpnpphphhhhpphnphnnpphpnhnhnhhhnphhhppnphnphnhhpnhphnhn

output:

23

result:

ok single line: '23'

Test #60:

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

input:

ebbbebeeeeebzzbezzbbbzebzebzeezzeebzzeeebzebebbezezebbeezzzbzbbeezezbbezezbeeebbzebzzezezbbeebzezee

output:

17

result:

ok single line: '17'

Test #61:

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

input:

hhhttatththhaahthhhataaaahaaaahahhaahhtttahhaataaahthhataahaahhttahaththhhhhahaatthaahatahaahaahtha

output:

21

result:

ok single line: '21'

Test #62:

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

input:

ycccsysccsscycsysyyycsyssssscycyyccccycyycssssysscsycscssscscyyycyysycsysyyccscyyscccyycysycsycyycs

output:

20

result:

ok single line: '20'

Test #63:

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

input:

hhphpjhhhjhjphjjpjhpphhhpjppphpjpphjhpppjhhjpphjjphpppjppphppjhhphjpjphjhppjhpppjjjhjhjhjjjjhppphph

output:

23

result:

ok single line: '23'

Test #64:

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

input:

assjjsssajajssssssasjsasjsjjajasjjassaassasaajjssjjsasasaasjjjjasaajsssasaaaasjssjajaasajsajsjsjjja

output:

20

result:

ok single line: '20'

Test #65:

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

input:

cwwkwkcwwcwwckwwwkkcwkcckkkwwcwcwkkkckwkwcwkcckkwkwkkcckckwkwcckcwcwkcwckkckwkwkkcwkkcwwkcccckkwwkk

output:

19

result:

ok single line: '19'

Test #66:

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

input:

plpwplwplpwllppllppllwwpwwwllplwlwwlplwplppwlplwlppwplllwwplpwlwppllpllwllwlwppwlpppwwwwwlppwwplwlp

output:

22

result:

ok single line: '22'

Test #67:

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

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: 3352kb

input:

wfwnfnfwccwnfcfwwnfwnfwfcccfccwffnwcncncfcwwnwwccccnnfwccffcfncwfccfwnnnwnwncccfcwfffcnfwwwwwwnncnc

output:

22

result:

ok single line: '22'

Test #70:

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

input:

bgbbwxbxggggxxwwwbbwxxgwgxwgwbxbgbwwwwbgggxwbwxgwxwbxgxwxwbwgbxwxxwwbxbbwxwgwgwxxgxgxwbwxgwxbbwxgbw

output:

23

result:

ok single line: '23'

Test #71:

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

input:

zwzwzzcwczzzzwcwmmzmcczwmwzzzwcccczzwzzzczwcwmccwzmccmwwcccwzcwzcwzmwwzwcmwcccwccwczmmzwzmwcwcwmmcc

output:

22

result:

ok single line: '22'

Test #72:

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

input:

abbbybbaxabbxbyyxbxbxxxxyybbayaabxaxabxybxbybbaaxbyybyyaxybayxyxybxbxbyyaxaybbyyyayyxxbxbabybxabxyy

output:

22

result:

ok single line: '22'

Test #73:

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

input:

grzrzrrrzggggrgzkzrkzrggkgkkkrgzrzkzzgzkrkzkgkkrzzgkzzrzrgkkzkzkgzrkgrgkzgrzrzkgkzrgkrrrrkrrkrrkkzg

output:

24

result:

ok single line: '24'

Test #74:

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

input:

xxmxyxdmdyymmxmmxdmyyyxmdmxymxyymmyyymdymyydxymyxxyyddmdydyxxdmxxdyxdmdyxyddxdxydxddmmyxyydymmymddm

output:

21

result:

ok single line: '21'

Test #75:

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

input:

grgffrrgfrrrfbfgbbrfggbrbbbgfrbgrbgfgfgbgfbrrrrrbfbgbbbbfffbfrrrrfrrbbgfgffrfbggrrrfbrrgrgfrffrbrgr

output:

24

result:

ok single line: '24'

Test #76:

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

input:

wgfguufuufgwfugwwugffgwgffgufgfufugwffgwuwguwufuguwuwwfwuwfguguuugfggufgufuwufuwfwwwwgwgwgfgffuuguu

output:

23

result:

ok single line: '23'