Submission #774454

#TimeUsernameProblemLanguageResultExecution timeMemory
774454RushBMutating DNA (IOI21_dna)C++17
100 / 100
33 ms7424 KiB
#include "dna.h" #include <bits/stdc++.h> #define FOR(i, a, b) for (int i = (a); i < (b); i++) using namespace std; const int N = 1e5 + 50; int ps[N][3][3], n; short T[256]; void init(string a, string b) { T['A'] = 0; T['T'] = 1; T['C'] = 2; n = a.size(); ps[0][T[a[0]]][T[b[0]]] = 1; FOR(i, 1, n) { FOR(j, 0, 3) FOR(k, 0, 3) ps[i][j][k] = ps[i - 1][j][k]; ps[i][T[a[i]]][T[b[i]]]++; } } int get_distance(int x, int y) { int dp[3][3]; memset(dp, 0, sizeof dp); FOR(i, 0, 3) FOR(j, 0, 3) dp[i][j] = ps[y][i][j] - (x ? ps[x - 1][i][j] : 0); int ans = 0; FOR(i, 0, 3) FOR(j, i + 1, 3) { int m = min(dp[i][j], dp[j][i]); ans += m; dp[i][j] -= m; dp[j][i] -= m; } { int m = min({dp[0][1], dp[1][2], dp[2][0]}); ans += 2 * m; dp[0][1] -= m, dp[1][2] -= m, dp[2][0] -= m; } { int m = min({dp[0][2], dp[2][1], dp[1][0]}); ans += 2 * m; dp[0][2] -= m, dp[2][1] -= m, dp[1][0] -= m; } FOR(i, 0, 3) FOR(j, i + 1, 3) if (dp[i][j] || dp[j][i]) return -1; return ans; }

Compilation message (stderr)

dna.cpp: In function 'void init(std::string, std::string)':
dna.cpp:14:14: warning: array subscript has type 'char' [-Wchar-subscripts]
   14 |  ps[0][T[a[0]]][T[b[0]]] = 1;
      |              ^
dna.cpp:14:23: warning: array subscript has type 'char' [-Wchar-subscripts]
   14 |  ps[0][T[a[0]]][T[b[0]]] = 1;
      |                       ^
dna.cpp:17:15: warning: array subscript has type 'char' [-Wchar-subscripts]
   17 |   ps[i][T[a[i]]][T[b[i]]]++;
      |               ^
dna.cpp:17:24: warning: array subscript has type 'char' [-Wchar-subscripts]
   17 |   ps[i][T[a[i]]][T[b[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...