Submission #437249

#TimeUsernameProblemLanguageResultExecution timeMemory
437249irmuunMutating DNA (IOI21_dna)C++17
Compilation error
0 ms0 KiB
#include<bits/stdc++.h>
#include "dna.h"
using namespace std;
string A,B;
int p[100000][3][3],i,c,d,e,f,g,j,k,h[3][3],ch[100000][3],ch1[100000][3],dif[2][3],ans;
void init(string a,string b){
  for(i=0;i<3;i++){
    ch[-1][i]=0;
    ch1[-1][i]=0;
    for(j=0;j<3;j++){
      p[-1][i][j]=0;
    }
  }
  for(i=0;i<a.size();i++){
    if(a[i]=='A'){
      d=0;
    }
    else if(a[i]=='C'){
      d=1;
    }
    else{
      d=2;
    }
    if(b[i]=='A'){
      e=0;
    }
    else if(b[i]=='C'){
      e=1;
    }
    else{
      e=2;
    }
    for(j=0;j<3;j++){
      if(j==d){
      	ch[i][j]=ch[i-1][j]+1;
      }
      else{
        ch[i][j]=ch[i-1][j];
      }
      if(j==e){
      	ch1[i][j]=ch1[i-1][j]+1;
      }
      else{
        ch1[i][j]=ch1[i-1][j];
      }
      for(k=0;k<3;k++){
        if(j==d&&k==e){
          p[i][j][k]=p[i-1][j][k]+1;
        }
        else{
          p[i][j][k]=p[i-1][j][k];
        }
      }
    }
  }
}
int get_distanse(int x,int y){
  ans=0;
  for(i=0;i<3;i++){
    dif[0][0]=ch[y][0]-ch[x-1][0];
    dif[0][1]=ch[y][1]-ch[x-1][1];
    dif[0][2]=ch[y][2]-ch[x-1][2];
    dif[1][0]=ch1[y][0]-ch1[x-1][0];
    dif[1][1]=ch1[y][1]-ch1[x-1][1];
    dif[1][2]=ch1[y][2]-ch1[x-1][2];
    for(j=0;j<3;j++){
      h[i][j]=p[y][i][j]-p[x-1][i][j];
    }
  }
  if(dif[0][0]!=dif[1][0]||dif[0][1]!=dif[1][1]||dif[0][2]!=dif[1][2]){
    return -1;
  }
  f=min(h[0][1],min(h[1][2],h[2][0]));
  g=min(h[1][0],min(h[2][1],h[0][2]));
  ans+=(f+g)*2;
  h[0][1]-=f;
  h[1][2]-=f;
  h[2][0]-=f;
  h[1][0]-=g;
  h[2][1]-=g;
  h[0][2]-=g;
  return ans+h[0][1]+h[1][2]+h[2][0];
}

Compilation message (stderr)

dna.cpp: In function 'void init(std::string, std::string)':
dna.cpp:14:12: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   14 |   for(i=0;i<a.size();i++){
      |           ~^~~~~~~~~
dna.cpp:8:10: warning: array subscript -1 is below array bounds of 'int [100000][3]' [-Warray-bounds]
    8 |     ch[-1][i]=0;
      |     ~~~~~^
dna.cpp:9:11: warning: array subscript -1 is below array bounds of 'int [100000][3]' [-Warray-bounds]
    9 |     ch1[-1][i]=0;
      |     ~~~~~~^
dna.cpp:11:11: warning: array subscript -1 is below array bounds of 'int [100000][3][3]' [-Warray-bounds]
   11 |       p[-1][i][j]=0;
      |       ~~~~^
dna.cpp:8:14: warning: 'void* __builtin_memset(void*, int, long unsigned int)' offset -12 is out of the bounds [0, 1200000] of object 'ch' with type 'int [100000][3]' [-Warray-bounds]
    8 |     ch[-1][i]=0;
      |     ~~~~~~~~~^~
dna.cpp:5:45: note: 'ch' declared here
    5 | int p[100000][3][3],i,c,d,e,f,g,j,k,h[3][3],ch[100000][3],ch1[100000][3],dif[2][3],ans;
      |                                             ^~
dna.cpp:9:15: warning: 'void* __builtin_memset(void*, int, long unsigned int)' offset -12 is out of the bounds [0, 1200000] of object 'ch1' with type 'int [100000][3]' [-Warray-bounds]
    9 |     ch1[-1][i]=0;
      |     ~~~~~~~~~~^~
dna.cpp:5:59: note: 'ch1' declared here
    5 | int p[100000][3][3],i,c,d,e,f,g,j,k,h[3][3],ch[100000][3],ch1[100000][3],dif[2][3],ans;
      |                                                           ^~~
dna.cpp:11:18: warning: 'void* __builtin_memset(void*, int, long unsigned int)' offset -36 is out of the bounds [0, 3600000] of object 'p' with type 'int [100000][3][3]' [-Warray-bounds]
   11 |       p[-1][i][j]=0;
      |       ~~~~~~~~~~~^~
dna.cpp:5:5: note: 'p' declared here
    5 | int p[100000][3][3],i,c,d,e,f,g,j,k,h[3][3],ch[100000][3],ch1[100000][3],dif[2][3],ans;
      |     ^
/usr/bin/ld: /tmp/cc628DJe.o: in function `main':
grader.cpp:(.text.startup+0x39d): undefined reference to `get_distance(int, int)'
collect2: error: ld returned 1 exit status