Submission #1216844

#TimeUsernameProblemLanguageResultExecution timeMemory
1216844islam_2010Mutating DNA (IOI21_dna)C++20
Compilation error
0 ms0 KiB
#pragma GCC optimize("O3")
#include "dna.h"
#include <bits/stdc++.h>
using namespace std;
string s, c;
int pref_diff[sz];

void init(string a, string b){
    s=a;
    c=b;
    pref_diff[0] = (a[0]!=b[0]);
    for(int i = 1; i < s.size(); i++){
        pref_diff[i] = pref_diff[i-1] + (a[i]!=b[i]);
    }
}

int get_distance(int x, int y){
    string ss=s.substr(x, y-x+1), cc=c.substr(x, y-x+1);
    string s2 = ss, c2=cc;
    sort(ss.begin(), ss.end());
    sort(cc.begin(), cc.end());
    if(ss!=cc){
        return -1;
    }
    if(s2==c2){
        return 0;
    }
    if(y-x<3){
        sort(ss.begin(), ss.end());
        sort(cc.begin(), cc.end());
        if(ss!=cc){
            return -1;
        }if(s2==c2){
            return 0;
        }if(y-x+1==1){
            return 0;
        }else if(y-x+1==2){
            return 1;
        }else {
            int cnt = 0;
            if(s2[0]!=c2[0]){
                cnt++;
            }if(s2[1]!=c2[1]){
                cnt++;
            }if(s2[2]!=c2[2]){
                cnt++;
            }if(cnt==2){
                return 1;
            }else {
                return 2;
            }
        }
    }else {
        int aa = pref_diff[y]-pref_diff[x-1];
        
        return aa/2;
    }
    
}

Compilation message (stderr)

dna.cpp:6:15: error: 'sz' was not declared in this scope; did you mean 's'?
    6 | int pref_diff[sz];
      |               ^~
      |               s
dna.cpp: In function 'void init(std::string, std::string)':
dna.cpp:11:5: error: 'pref_diff' was not declared in this scope
   11 |     pref_diff[0] = (a[0]!=b[0]);
      |     ^~~~~~~~~
dna.cpp: In function 'int get_distance(int, int)':
dna.cpp:54:18: error: 'pref_diff' was not declared in this scope
   54 |         int aa = pref_diff[y]-pref_diff[x-1];
      |                  ^~~~~~~~~