제출 #437657

#제출 시각아이디문제언어결과실행 시간메모리
437657FireGhost1301DNA 돌연변이 (IOI21_dna)C++17
100 / 100
54 ms4896 KiB
/** __author__ : FireGhost problems_ID: ioi21_dna */ #include "dna.h" #include <bits/stdc++.h> using namespace std; #define mp make_pair #define pb push_back #define eb emplace_back #define fi first #define se second #define all(x) x.begin(), x.end() typedef long long ll; typedef unsigned long long ull; typedef pair<int, int> pii; const int N = 1e5 + 3; const int MOD = 1e9 + 7; int pref_AT[N], pref_TA[N], pref_AC[N], pref_CA[N], pref_TC[N], pref_CT[N]; void init(string a, string b) { int n = a.size(); a = " " + a; b = " " + b; for (int i = 1; i <= n; ++i) { pref_AT[i] = pref_AT[i - 1] + (a[i] == 'A' && b[i] == 'T'); pref_TA[i] = pref_TA[i - 1] + (a[i] == 'T' && b[i] == 'A'); pref_AC[i] = pref_AC[i - 1] + (a[i] == 'A' && b[i] == 'C'); pref_CA[i] = pref_CA[i - 1] + (a[i] == 'C' && b[i] == 'A'); pref_TC[i] = pref_TC[i - 1] + (a[i] == 'T' && b[i] == 'C'); pref_CT[i] = pref_CT[i - 1] + (a[i] == 'C' && b[i] == 'T'); } } int get_distance(int x, int y) { ++x, ++y; int ans = 0; int AT = pref_AT[y] - pref_AT[x - 1]; int TA = pref_TA[y] - pref_TA[x - 1]; int AC = pref_AC[y] - pref_AC[x - 1]; int CA = pref_CA[y] - pref_CA[x - 1]; int TC = pref_TC[y] - pref_TC[x - 1]; int CT = pref_CT[y] - pref_CT[x - 1]; int i = min(AT, TA), j = min(AC, CA), k = min(TC, CT); ans += i + j + k; AT -= i, TA -= i, AC -= j, CA -= j, TC -= k, CT -= k; int A = AT + AC - TA - CA, C = CA + CT - AC - TC, T = TA + TC - AT - CT; if (A > 0 || T > 0 || C > 0) return -1; if (AT == 0) { if (TA != AC || AC != CT) return -1; ans += 2 * TA; } else { if (AT != TC || TC != CA) return -1; ans += 2 * AT; } 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...