Submission #499833

#TimeUsernameProblemLanguageResultExecution timeMemory
499833sazid_alamMutating DNA (IOI21_dna)C++17
100 / 100
48 ms9708 KiB
#include "dna.h" #include <bits/stdc++.h> using namespace std; int tot[100005][3][2], bad[100005][3][3]; void init(string u, string v) { for(int i = 0; i < u.size(); i++){ for(int j = 0; j < 3; j++){ for(int k = 0; k < 3; k++){ bad[i + 1][j][k] += bad[i][j][k]; } } if(u[i] != v[i]){ if(u[i] == 'A' && v[i] == 'C') bad[i + 1][0][1]++; if(u[i] == 'A' && v[i] == 'T') bad[i + 1][0][2]++; if(u[i] == 'C' && v[i] == 'A') bad[i + 1][1][0]++; if(u[i] == 'C' && v[i] == 'T') bad[i + 1][1][2]++; if(u[i] == 'T' && v[i] == 'A') bad[i + 1][2][0]++; if(u[i] == 'T' && v[i] == 'C') bad[i + 1][2][1]++; } if(u[i] == 'A') tot[i + 1][0][0]++; if(v[i] == 'A') tot[i + 1][0][1]++; if(u[i] == 'C') tot[i + 1][1][0]++; if(v[i] == 'C') tot[i + 1][1][1]++; if(u[i] == 'T') tot[i + 1][2][0]++; if(v[i] == 'T') tot[i + 1][2][1]++; for(int j = 0; j < 3; j++){ tot[i + 1][j][0] += tot[i][j][0]; tot[i + 1][j][1] += tot[i][j][1]; } } } int get_distance(int x, int y) { for(int j = 0; j < 3; j++){ if(tot[y + 1][j][0] - tot[x][j][0] != tot[y + 1][j][1] - tot[x][j][1]) return -1; } int ans = 0, extra = 1000000; bool done[3][3] = {0}; for(int j = 0; j < 3; j++){ for(int k = 0; k < 3; k++){ if(done[j][k] || done[k][j] || j == k) continue; int ch = min(bad[y + 1][j][k] - bad[x][j][k], bad[y + 1][k][j] - bad[x][k][j]); int hc = max(bad[y + 1][j][k] - bad[x][j][k], bad[y + 1][k][j] - bad[x][k][j]); ans += ch; extra = min(extra, hc - ch); done[j][k] = true; } } return ans + extra * 2; }

Compilation message (stderr)

dna.cpp: In function 'void init(std::string, std::string)':
dna.cpp:8:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    8 |     for(int i = 0; i < u.size(); i++){
      |                    ~~^~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...