Submission #1142211

#TimeUsernameProblemLanguageResultExecution timeMemory
1142211programming23Mutating DNA (IOI21_dna)C++20
Compilation error
0 ms0 KiB
void init(string a, string b) { stringA = a; stringB = b; int ln = stringA.size(); arrCount.resize(ln); int count = 0; for(int i=ln-1; i>0;i--){ if (stringA[i] != stringB[i]){ count+=1; } arrCount[i] = count; } } int get_distance(int x, int y) { string sA = stringA; string sB = stringB; map<char, int> countsB; map<char, int> countsA; int ln = sA.size(); int count = 0; for(int i=x; i <= y; i++){ if(countsA.find(sA[i]) == countsA.end()){ countsA[sA[i]] = 1; }else{ countsA[sA[i]] +=1; } if(countsB.find(sB[i]) == countsB.end()){ countsB[sB[i]] = 1; }else{ countsB[sB[i]] +=1; } } int lnA = countsA.size(); int lnB = countsB.size(); if(lnA != lnB){ return -1; }for(auto c: countsA){ if(countsA[c.first] != countsB[c.first]){ return -1; } } if(lnA == 2 && lnB == 2){ count = arrCount[0]; if(y+1 <= ln){ count-=arrCount[y+1]; } if(x-1 >= 0){ count -= arrCount[x-1]; } return count/2; } int i=x; while (i <= y && sA != sB){ char c = sA[i]; if(c == sB[i]){ i++; continue; } for(int z=i+1; z <= y; z++){ if(sA[z] != sB[i] || sA[z] == sB[z]){ continue; } sA[i] = sA[z]; sA[z] = c; i++; count++; } } return count; }

Compilation message (stderr)

dna.cpp:2:6: error: variable or field 'init' declared void
    2 | void init(string a, string b) {
      |      ^~~~
dna.cpp:2:11: error: 'string' was not declared in this scope
    2 | void init(string a, string b) {
      |           ^~~~~~
dna.cpp:2:21: error: 'string' was not declared in this scope
    2 | void init(string a, string b) {
      |                     ^~~~~~
dna.cpp: In function 'int get_distance(int, int)':
dna.cpp:18:9: error: 'string' was not declared in this scope
   18 |         string sA = stringA;
      |         ^~~~~~
dna.cpp:19:15: error: expected ';' before 'sB'
   19 |         string sB = stringB;
      |               ^~~
      |               ;
dna.cpp:20:9: error: 'map' was not declared in this scope
   20 |         map<char, int> countsB;
      |         ^~~
dna.cpp:20:13: error: expected primary-expression before 'char'
   20 |         map<char, int> countsB;
      |             ^~~~
dna.cpp:21:13: error: expected primary-expression before 'char'
   21 |         map<char, int> countsA;
      |             ^~~~
dna.cpp:22:14: error: 'sA' was not declared in this scope
   22 |     int ln = sA.size();
      |              ^~
dna.cpp:25:20: error: 'countsA' was not declared in this scope; did you mean 'count'?
   25 |                 if(countsA.find(sA[i]) == countsA.end()){
      |                    ^~~~~~~
      |                    count
dna.cpp:30:20: error: 'countsB' was not declared in this scope; did you mean 'count'?
   30 |                 if(countsB.find(sB[i]) == countsB.end()){
      |                    ^~~~~~~
      |                    count
dna.cpp:30:33: error: 'sB' was not declared in this scope
   30 |                 if(countsB.find(sB[i]) == countsB.end()){
      |                                 ^~
dna.cpp:36:15: error: 'countsA' was not declared in this scope; did you mean 'count'?
   36 |     int lnA = countsA.size();
      |               ^~~~~~~
      |               count
dna.cpp:37:15: error: 'countsB' was not declared in this scope; did you mean 'count'?
   37 |     int lnB = countsB.size();
      |               ^~~~~~~
      |               count
dna.cpp:46:17: error: 'arrCount' was not declared in this scope
   46 |         count = arrCount[0];
      |                 ^~~~~~~~
dna.cpp:57:28: error: 'sB' was not declared in this scope
   57 |     while (i <= y && sA != sB){
      |                            ^~