Submission #550781

#TimeUsernameProblemLanguageResultExecution timeMemory
550781topovikMutating DNA (IOI21_dna)C++17
56 / 100
70 ms8144 KiB
#include <bits/stdc++.h> #include "dna.h" #define pb push_back #define f first #define s second using namespace std; typedef long long ll; typedef long double ld; typedef unsigned long long ull; const ll oo = 1e9 + 7; const ll N = 1e6; const ll M = 21; const ll M1 = 1e6; int pref[N][3][3]; int A[N]; int B[N]; void init(string a, string b) { int n = a.size(); for (int i = 0; i < n; i++) { if (a[i] == 'T') A[i] = 1; if (a[i] == 'C') A[i] = 2; if (b[i] == 'T') B[i] = 1; if (b[i] == 'C') B[i] = 2; } pref[0][A[0]][B[0]]++; for (int i = 1; i < n; i++) { for (int j = 0; j < 3; j++) for (int j1 = 0; j1 < 3; j1++) pref[i][j][j1] = pref[i - 1][j][j1]; pref[i][A[i]][B[i]]++; } } int get_distance(int x, int y) { vector <vector <int> > vc(3); for (int i = 0; i < 3; i++) vc[i].resize(3); for (int i = 0; i < 3; i++) for (int j = 0; j < 3; j++) if (x > 0) vc[i][j] = pref[y][i][j] - pref[x - 1][i][j]; else vc[i][j] = pref[y][i][j]; int ans = 0; for (int o = 0; o < 3; o++) { for (int i = 0; i < 3; i++) for (int j = 0; j < 3; j++) if (i != j) { int c = min(vc[i][j], vc[j][i]); ans += c; vc[i][j] -= c; vc[i][j] -= c; } for (int i = 0; i < 3; i++) for (int j = 0; j < 3; j++) if (i != j && vc[i][j] > 0) for (int j1 = 0; j1 < 3; j1++) if (j1 != j && vc[j][j1] > 0) { int c = min(vc[i][j], vc[j][j1]); vc[i][j1] += c; vc[j][j1] -= c; vc[i][j] -= c; ans += c; } } for (int i = 0; i < 3; i++) for (int j = 0; j < 3; j++) if (i != j && vc[i][j] > 0) return -1; return ans; } //int main() //{ // ios_base::sync_with_stdio(0); // iostream::sync_with_stdio(0); // cin.tie(0); // cout.tie(0); // int n, q; // cin >> n >> q; // string a, b; // cin >> a >> b; // init(a, b); // while (q--) // { // int x, y; // cin >> x >> y; // cout << get_distance(x, y) << endl; // } //} /* 5 3 2 1 1 2 2 3 2 3 3 4 4 5 4 1 1 2 2 3 3 4 4 5 */
#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...