Submission #1007521

#TimeUsernameProblemLanguageResultExecution timeMemory
1007521stdfloatMutating DNA (IOI21_dna)C++17
100 / 100
55 ms23632 KiB
#include <bits/stdc++.h> #include "dna.h" using namespace std; vector<vector<vector<int>>> v; void init(string a, string b) { int n = (int)a.size(); for (int i = 0; i < n; i++) { a[i] = (a[i] == 'A' ? '0' : (a[i] == 'T' ? '1' : '2')); b[i] = (b[i] == 'A' ? '0' : (b[i] == 'T' ? '1' : '2')); } v.assign(n, vector<vector<int>>(3, vector<int>(3))); for (int i = 0; i < n; i++) { for (int j = 0; j < 3; j++) { for (int k = 0; k < 3; k++) v[i][j][k] = (i ? v[i - 1][j][k] : 0) + (j == b[i] - '0' && k == a[i] - '0' && a[i] != b[i]); } } } int get_distance(int x, int y) { vector<vector<int>> cnt(3, vector<int>(3)); for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) cnt[i][j] = v[y][i][j] - (x ? v[x - 1][i][j] : 0); } int ans = 0; for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { int mn = min(cnt[i][j], cnt[j][i]); ans += mn; cnt[i][j] -= mn; cnt[j][i] -= mn; } } return (cnt[0][1] + cnt[0][2] == cnt[1][0] + cnt[1][2] && cnt[1][0] + cnt[1][2] == cnt[2][0] + cnt[2][1] ? ans + (cnt[0][1] + cnt[0][2] << 1) : -1); }

Compilation message (stderr)

dna.cpp: In function 'int get_distance(int, int)':
dna.cpp:36:126: warning: suggest parentheses around '+' inside '<<' [-Wparentheses]
   36 |  return (cnt[0][1] + cnt[0][2] == cnt[1][0] + cnt[1][2] && cnt[1][0] + cnt[1][2] == cnt[2][0] + cnt[2][1] ? ans + (cnt[0][1] + cnt[0][2] << 1) : -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...