Submission #442955

#TimeUsernameProblemLanguageResultExecution timeMemory
442955ltf0501Mutating DNA (IOI21_dna)C++17
100 / 100
46 ms7404 KiB
#include "dna.h" #include <bits/stdc++.h> using namespace std; const int kN = 1e5 + 10; int n, pre[kN][3][3]; map<char, int> mp; void init(std::string a, std::string b) { mp['A'] = 0, mp['T'] = 1, mp['C'] = 2; n = a.length(); for(int i = 0; i < n; i++) { if(i) { for(int x = 0; x < 3; x++) { for(int y = 0; y < 3; y++) pre[i][x][y] = pre[i - 1][x][y]; } } pre[i][mp[a[i]]][mp[b[i]]]++; } } int get_distance(int l, int r) { auto Getnum = [&](int x, int y) { if(!l) return pre[r][x][y]; else return pre[r][x][y] - pre[l - 1][x][y]; }; int num[3][3] = {}; for(int i = 0; i < 3; i++) { for(int j = 0; j < 3; j++) num[i][j] = Getnum(i, j); } int cnt = 0; for(int i = 0; i < 3; i++) { int j = (i + 1) % 3; int mn = min(num[i][j], num[j][i]); cnt += mn; num[i][j] -= mn, num[j][i] -= mn; } bool flag = 1; for(int i = 0; i < 3; i++) flag &= (num[i][(i + 1) % 3] == num[0][1]); for(int i = 0; i < 3; i++) flag &= (num[(i + 1) % 3][i] == num[1][0]); if(!flag) return -1; else { cnt += 2 * (num[0][1] + num[1][0]); return cnt; } }
#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...