Submission #636747

#TimeUsernameProblemLanguageResultExecution timeMemory
636747imeimi2000Mutating DNA (IOI21_dna)C++17
100 / 100
41 ms7364 KiB
#include "dna.h" #include <cstring> #include <algorithm> using namespace std; int n; int cnt[100005][3][3]; void init(string a, string b) { n = a.size(); int C[256]; C['A'] = 0; C['C'] = 1; C['T'] = 2; for (int i = 1; i <= n; ++i) { memcpy(cnt[i], cnt[i - 1], sizeof(cnt[i])); ++cnt[i][C[a[i - 1]]][C[b[i - 1]]]; } } int get_distance(int x, int y) { int D[3][3]; memcpy(D, cnt[y + 1], sizeof(D)); for (int i = 0; i < 3; ++i) for (int j = 0; j < 3; ++j) D[i][j] -= cnt[x][i][j]; int ans = 0; for (int i = 0; i < 3; ++i) { for (int j = i + 1; j < 3; ++j) { int v = min(D[i][j], D[j][i]); ans += v; D[i][j] -= v; D[j][i] -= v; } } int v = min({ D[0][1], D[1][2], D[2][0] }); D[0][1] -= v; D[1][2] -= v; D[2][0] -= v; ans += v + v; v = min({ D[1][0], D[2][1], D[0][2] }); D[1][0] -= v; D[2][1] -= v; D[0][2] -= v; ans += v + v; for (int i = 0; i < 3; ++i) for (int j = 0; j < 3; ++j) if (i != j && D[i][j]) return -1; return ans; }

Compilation message (stderr)

dna.cpp: In function 'void init(std::string, std::string)':
dna.cpp:17:22: warning: array subscript has type 'char' [-Wchar-subscripts]
   17 |   ++cnt[i][C[a[i - 1]]][C[b[i - 1]]];
      |                      ^
dna.cpp:17:35: warning: array subscript has type 'char' [-Wchar-subscripts]
   17 |   ++cnt[i][C[a[i - 1]]][C[b[i - 1]]];
      |                                   ^
#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...