Submission #570477

#TimeUsernameProblemLanguageResultExecution timeMemory
570477jack715Mutating DNA (IOI21_dna)C++17
100 / 100
98 ms23484 KiB
#include "dna.h" #include <bits/stdc++.h> #define ll long long #define pb push_back #define pp pop_back #define mp make_pair #define bb back #define ff first #define ss second using namespace std; vector<vector<vector<int> > > cnt; void init(std::string a, std::string b) { int n = a.size(); cnt.resize(n, vector<vector<int> > (3, vector<int>(3, 0))); for (int i = 0; i < n; i++) { if (a[i] == 'T') a[i] = 'B'; if (b[i] == 'T') b[i] = 'B'; if (i) cnt[i] = cnt[i-1]; cnt[i][a[i]-'A'][b[i]-'A']++; } } int get_distance(int x, int y) { vector<vector<int> > tmp(3, vector<int>(3)); for (int i = 0; i < 3; i++) for (int j = 0; j < 3; j++) { tmp[i][j] = cnt[y][i][j] - (x > 0 ? cnt[x-1][i][j] : 0); } int ans = 0; vector<int> rem(3, 0); for (int i = 0; i < 3; i++) for (int j = 0; j < 3; j++) { if (i == j) continue; if (tmp[i][j] < tmp[j][i]) { ans += tmp[i][j]; tmp[j][i] -= tmp[i][j]; tmp[i][j] = 0; } else { ans += tmp[j][i]; tmp[i][j] -= tmp[j][i]; tmp[j][i] = 0; } rem[i] += tmp[i][j]; } ans += rem[0] + rem[1]; if (rem[0] != rem[1] || rem[1] != rem[2]) return -1; return ans; }
#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...