Submission #1142643

#TimeUsernameProblemLanguageResultExecution timeMemory
1142643mouataz_the_giantMutating DNA (IOI21_dna)C++17
Compilation error
0 ms0 KiB
#include <bits/stdc++.h> #include "dna.h" using namespace std; void init(string x,string y); int get_distance(int x,int y); string u,v; void init(string a,string b){ u = a; v = b; } int get_distance(int x,int y){ int t1 = 0; int t2 = 0; int a1 = 0; int a2 = 0; int c1 = 0; int c2 = 0; int pot = 0; int ans = 0; int t_a = 0; int a_t = 0; int a_c = 0; int c_a = 0; int t_c = 0; int c_t = 0; string a1 = u.substr(x,y-x+1); string b1 = v.substr(x,y-x+1); for(int i = 0;i < a1.length();i++){ if(a[i] == 'T'){ t1++; } if(b[i] == 'T'){ t2++; } if(a[i] == 'A'){ a1++; } if(b[i] == 'A'){ a2++; } if(a[i] == 'C'){ c1++; } if(b[i] == 'C'){ c2++; } if(a1[i] == 'T' && b1[i] == 'A'){ t_a++; } if(a1[i] == 'A' && b1[i] == 'T'){ a_t++; } if(a1[i] == 'A' && b1[i] == 'C'){ a_c++; } if(a1[i] == 'C' && b1[i] == 'A'){ c_a++; } if(a1[i] == 'T' && b1[i] == 'C'){ t_c++; } if(a1[i] == 'C' && b1[i] == 'T'){ c_t++; } } if(((c1 != c2) || (t1 != t2)) || (a1 != a2)){ return -1; } ans += min(a_c,c_a); ans += min(t_a,a_t); ans += min(t_c,c_t); pot += max(a_c,c_a) - min(a_c,c_a); pot += max(a_t,t_a) - min(a_t,t_a); pot += max(t_c,c_t) - min(t_c,c_t); ans += (pot/3) * 2; return ans; }

Compilation message (stderr)

dna.cpp: In function 'int get_distance(int, int)':
dna.cpp:28:12: error: conflicting declaration 'std::string a1'
   28 |     string a1 = u.substr(x,y-x+1);
      |            ^~
dna.cpp:16:9: note: previous declaration as 'int a1'
   16 |     int a1 = 0;
      |         ^~
dna.cpp:30:26: error: request for member 'length' in 'a1', which is of non-class type 'int'
   30 |     for(int i = 0;i < a1.length();i++){
      |                          ^~~~~~
dna.cpp:31:12: error: 'a' was not declared in this scope
   31 |         if(a[i] == 'T'){
      |            ^
dna.cpp:34:12: error: 'b' was not declared in this scope
   34 |         if(b[i] == 'T'){
      |            ^
dna.cpp:37:12: error: 'a' was not declared in this scope
   37 |         if(a[i] == 'A'){
      |            ^
dna.cpp:40:12: error: 'b' was not declared in this scope
   40 |         if(b[i] == 'A'){
      |            ^
dna.cpp:43:12: error: 'a' was not declared in this scope
   43 |         if(a[i] == 'C'){
      |            ^
dna.cpp:46:12: error: 'b' was not declared in this scope
   46 |         if(b[i] == 'C'){
      |            ^
dna.cpp:49:14: error: invalid types 'int[int]' for array subscript
   49 |         if(a1[i] == 'T' && b1[i] == 'A'){
      |              ^
dna.cpp:52:14: error: invalid types 'int[int]' for array subscript
   52 |         if(a1[i] == 'A' && b1[i] == 'T'){
      |              ^
dna.cpp:55:14: error: invalid types 'int[int]' for array subscript
   55 |         if(a1[i] == 'A' && b1[i] == 'C'){
      |              ^
dna.cpp:58:14: error: invalid types 'int[int]' for array subscript
   58 |         if(a1[i] == 'C' && b1[i] == 'A'){
      |              ^
dna.cpp:61:14: error: invalid types 'int[int]' for array subscript
   61 |         if(a1[i] == 'T' && b1[i] == 'C'){
      |              ^
dna.cpp:64:14: error: invalid types 'int[int]' for array subscript
   64 |         if(a1[i] == 'C' && b1[i] == 'T'){
      |              ^