CSES - Aalto Competitive Programming 2024 - wk3 - Wed - Results
Submission details
Task:Spin-Pop-Squeeze-Clap
Sender:aalto2024c_007
Submission time:2024-09-18 17:04:44 +0300
Language:C++ (C++20)
Status:READY
Result:
Test results
testverdicttime
#1ACCEPTED0.00 sdetails
#2ACCEPTED0.00 sdetails
#30.00 sdetails
#4ACCEPTED0.00 sdetails
#5ACCEPTED0.00 sdetails
#60.06 sdetails
#70.01 sdetails
#80.04 sdetails
#90.02 sdetails
#10ACCEPTED0.01 sdetails
#110.01 sdetails
#12ACCEPTED0.01 sdetails
#130.02 sdetails
#140.01 sdetails
#150.01 sdetails
#160.03 sdetails
#170.02 sdetails
#180.01 sdetails
#190.01 sdetails
#200.00 sdetails
#21ACCEPTED0.01 sdetails
#220.03 sdetails
#230.02 sdetails
#24ACCEPTED0.02 sdetails
#250.03 sdetails
#260.05 sdetails
#270.01 sdetails
#280.06 sdetails
#290.06 sdetails
#300.04 sdetails
#310.02 sdetails
#320.03 sdetails
#330.04 sdetails
#340.01 sdetails
#350.03 sdetails

Compiler report

input/code.cpp: In function 'void init(const string&, const string&)':
input/code.cpp:40:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   40 |     for(int i=0; i<a.size(); i++) s1[i] = (int)a[i] - (int)('0');
      |                  ~^~~~~~~~~
input/code.cpp:41:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   41 |     for(int i=0; i<b.size(); i++) s2[i] = (int)b[i] - (int)('0');
      |                  ~^~~~~~~~~

Code

#include <bits/stdc++.h>

using namespace std;

typedef unsigned long long ull;
typedef long long ll;

static int8_t s1[1001];
static int8_t s2[1001];
static int n, m;
static int costs[1001][1001];

inline int cost(int a, int b){
    return s1[a] != s2[b];
}

void makeCosts(){
    costs[0][0] = 0;
    for(int i=0; i<n; i++){
        costs[i][0] = i;
    }
    for(int j=0; j<m; j++){
        costs[0][j] = j;
    }

    for(int j=1; j<m; j++){
        for(int i=1; i<n; i++){
            if(i == 0 && j == 0)
                continue;
            costs[i][j] = min({
                costs[i-1][j] + 1,
                costs[i][j-1] + 1,
                costs[i-1][j-1] + cost(i,j),
            });
        }
    }
}

void init(const string& a, const string& b){
    for(int i=0; i<a.size(); i++) s1[i] = (int)a[i] - (int)('0');
    for(int i=0; i<b.size(); i++) s2[i] = (int)b[i] - (int)('0');

    makeCosts();
}

int main(){
    string a, b;
    cin >> a;
    cin >> b;

    if(b.size() > a.size())
        swap(a,b);

    n = a.size();
    m = b.size();

    vector<ull> distances;

    for(int c=0; c<10; c++){
        init(a, b);
        for(int i=0; i<n; i++) s1[i] = (s1[i] + i) % 10;
        for(int i=0; i<m; i++) s2[i] = (s2[i] + i) % 10;

        makeCosts();
        auto d = costs[n-1][m-1];
        distances.push_back(c + d);
    }

    cout << *min_element(distances.begin(), distances.end()) << endl;

    return 0;
}

Test details

Test 1

Verdict: ACCEPTED

input
111222
283303

correct output
4

user output
4

Test 2

Verdict: ACCEPTED

input
123123
54545

correct output
4

user output
4

Test 3

Verdict:

input
111
222

correct output
1

user output
2

Test 4

Verdict: ACCEPTED

input
999
999

correct output
0

user output
0

Test 5

Verdict: ACCEPTED

input
450
57

correct output
2

user output
2

Test 6

Verdict:

input
660487647593824219489241157815...

correct output
674

user output
671

Test 7

Verdict:

input
914177763170669074391500080636...

correct output
130

user output
128

Test 8

Verdict:

input
011524493909266858784005756682...

correct output
681

user output
675

Test 9

Verdict:

input
982597919074833788762328601290...

correct output
717

user output
718

Test 10

Verdict: ACCEPTED

input
416721106840388542143044324451...

correct output
215

user output
215

Test 11

Verdict:

input
458073021573681930364262129972...

correct output
473

user output
476

Test 12

Verdict: ACCEPTED

input
917400297550473688139849165156...

correct output
699

user output
699

Test 13

Verdict:

input
260181590830166131860913909960...

correct output
584

user output
579

Test 14

Verdict:

input
562301238360777679361730486761...

correct output
284

user output
283

Test 15

Verdict:

input
954220587915890627622301289161...

correct output
416

user output
415

Test 16

Verdict:

input
067903774208751350629566447245...

correct output
442

user output
451

Test 17

Verdict:

input
877893287921742180967929081003...

correct output
358

user output
350

Test 18

Verdict:

input
485260574793809275253093185610...

correct output
442

user output
443

Test 19

Verdict:

input
423232218340629042147624537896...

correct output
192

user output
198

Test 20

Verdict:

input
983444174766143554582284201195...

correct output
83

user output
80

Test 21

Verdict: ACCEPTED

input
308023002531575464533553486397...

correct output
984

user output
984

Test 22

Verdict:

input
774637064330445294039402907794...

correct output
544

user output
533

Test 23

Verdict:

input
645428410366485628023288358114...

correct output
378

user output
383

Test 24

Verdict: ACCEPTED

input
175337727474341582323359837344...

correct output
695

user output
695

Test 25

Verdict:

input
081836584929414654154099313187...

correct output
493

user output
502

Test 26

Verdict:

input
241592066112579763355561876139...

correct output
630

user output
641

Test 27

Verdict:

input
664737828830059612330669705871...

correct output
559

user output
557

Test 28

Verdict:

input
230972151340592860909446321989...

correct output
696

user output
701

Test 29

Verdict:

input
410946685234703970117608650309...

correct output
691

user output
694

Test 30

Verdict:

input
692323212407710827747149254185...

correct output
536

user output
530

Test 31

Verdict:

input
034704049619193895285878119956...

correct output
467

user output
472

Test 32

Verdict:

input
336980270982636303223976539004...

correct output
543

user output
540

Test 33

Verdict:

input
744311485456233719196607507429...

correct output
570

user output
580

Test 34

Verdict:

input
289232763326229330631165228849...

correct output
563

user output
568

Test 35

Verdict:

input
159941856600173517598637236698...

correct output
431

user output
420