Submission #1176117

#TimeUsernameProblemLanguageResultExecution timeMemory
1176117gygDNA 돌연변이 (IOI21_dna)C++20
100 / 100
128 ms6352 KiB
#include "dna.h" #include <bits/stdc++.h> using namespace std; #define arr array #define hmap unordered_map #define mp make_pair #define fir first #define sec second const int N = 1e5 + 5; int n; arr<char, N> a, b; hmap<string, arr<int, N>> sm; void sm_cmp() { for (int i = 1; i <= n; i++) { string x = ""; x += a[i], x += b[i]; for (string y : {"AA", "AC", "AT", "CC", "CA", "CT", "TT", "TA", "TC"}) { sm[y][i] = sm[y][i - 1] + (x == y); } } // for (int i = 1; i <= n; i++) // cout << i << ": " << sm["AT"][i] << '\n'; } void init(string _a, string _b) { n = _a.size(); for (int i = 1; i <= n; i++) a[i] = _a[i - 1], b[i] = _b[i - 1]; sm_cmp(); } int get_distance(int l, int r) { l++, r++; hmap<string, int> cnt; for (string x : {"AC", "AT", "CA", "CT", "TA", "TC"}) { cnt[x] = sm[x][r] - sm[x][l - 1]; } if (cnt["AT"] + cnt["AC"] != cnt["TA"] + cnt["CA"]) return -1; if (cnt["CT"] + cnt["CA"] != cnt["AC"] + cnt["TC"]) return -1; int ans = 0; for (pair<string, string> x : {mp("AT", "TA"), mp("AC", "CA"), mp("CT", "TC")}) { int rmv = min(cnt[x.fir], cnt[x.sec]); ans += rmv, cnt[x.fir] -= rmv, cnt[x.sec] -= rmv; } int mx = 0; for (string x : {"AC", "AT", "CA", "CT", "TA", "TC"}) { mx = max(mx, cnt[x]); } ans += 2 * mx; 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...