Submission #1001987

#TimeUsernameProblemLanguageResultExecution timeMemory
1001987vjudge1Mutating DNA (IOI21_dna)C++17
Compilation error
0 ms0 KiB
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define f first
#define s second
#define pb push_back
#define pf push_front
#define pi pair<int,int>

string a,b;
const int MAX = 1e5+10;
int n;
 
ll hold[MAX+1];
 ll how[2][MAX][3];

map<char,int>mtch;
void init(string A, string B){

    a = A;
   
    b = B;
   
   mtch['A']=0;
    mtch['C']=1;
    mtch['T']=2;
    for(int i = 0; i <a.size(); i++){
        for(int j = 0; j<3; j++){
            how[0][i+1][j] = how[0][i][j] ;
            how[1][i+1][j] = how[1][i][j] ;
         //   cnt[i+1][j] = cnt[i][j];
        }
       // cout << mtch[A[i]]<<" s "<< mtch[B[i]]<<endl;
        how[0][i+1][mtch[A[i]]]++;
        how[1][i+1][mtch[B[i]]]++;
        
       
    }
    for(int i = 1; i <=a.size(); i++){
        hold[i] =hold[i-1];
       if(A[i-1]!=B[i-1]){
           
            hold[i]++;
        }
    }
}


int get_distance(int x, int y){
//    cout << y << " " << x << endl;
  //  cout << hold[y+1] << " " << hold[x] << endl;
    ll add = hold[y+1]-hold[x] ;
    int vala,valb;
    for(int i =0; i < 3; i++){

         vala = how[0][y+1][i]-how[0][x][i];
         valb =  how[1][y+1][i]-how[1][x][i];
       //  cout<< vala<<" " << valb << endl;
        if(vala!=valb) return -1;
    }
  //  if(add==0) return 0;
    return (add+1)/2;
}


int main(){
    int n,q ;
    cin >> n >> q;
    string a,b;
    cin >> a >>b;
    
    init(a,b);
    int x,y;
    while(q--){
        cin >> x >>y;
        cout << get_distance(x,y)<<endl;
    }
}

Compilation message (stderr)

dna.cpp: In function 'void init(std::string, std::string)':
dna.cpp:27:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   27 |     for(int i = 0; i <a.size(); i++){
      |                    ~~^~~~~~~~~
dna.cpp:39:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   39 |     for(int i = 1; i <=a.size(); i++){
      |                    ~~^~~~~~~~~~
/usr/bin/ld: /tmp/ccCbxdKn.o: in function `main':
grader.cpp:(.text.startup+0x0): multiple definition of `main'; /tmp/ccLIy8hl.o:dna.cpp:(.text.startup+0x0): first defined here
collect2: error: ld returned 1 exit status