제출 #600331

#제출 시각아이디문제언어결과실행 시간메모리
600331OrazBDNA 돌연변이 (IOI21_dna)C++17
0 / 100
1497 ms59408 KiB
#include <bits/stdc++.h> #include "dna.h" #define N 100005 #define wr cout << "Continue debugging\n"; #define ll long long int #define pii pair <string, int> #define pb push_back #define ff first #define ss second using namespace std; map <pii, int> pr; map <string, int> m; vector <string> v = {"AT", "TA", "AC", "CA", "CT", "TC"}; int calc(){ int x = 0; for (auto s : v){ string c = ""; c += s[1]; c += s[0]; int mn = min(m[s], m[c]); x += mn; m[s] -= mn; m[c] -= mn; } return x; } void init(string a, string b){ int n = a.size(); a = ' ' + a; b = ' ' + b; for (int i = 1; i <= n; i++){ if (a[i] != b[i]){ string s = ""; s += a[i]; s += b[i]; //cout << i << " " << s << endl; pr[{s, i}] = 1; } } for (int i = 2; i <= n; i++){ for (auto s : v) pr[{s, i}] += pr[{s, i - 1}]; } // for (int i = 1; i <= n; i++){ // cout << pr[{"TC", i}] << " "; // } } int get_distance(int l, int r){ m.clear(); int ans = 0; for (auto s : v) m[s] = pr[{s, r}] - pr[{s, l - 1}]; // for (auto i : v){ // cout << m[i] << endl; // } ans += calc(); for (auto s : v){ string c = "", t1 = ""; c += s[1]; if ('A' != s[0] and 'A' != s[1]) c += 'A'; else if ('T' != s[0] and 'T' != s[1]) c += 'T'; else c += 'C'; t1 += s[0]; t1 += c[1]; int mn = min(m[s], m[c]); ans += mn; m[s] -= mn; m[c] -= mn; m[t1] += mn; } ans += calc(); for (auto i : v) if (m[i]) return -1; return ans; } // int main () // { // ios::sync_with_stdio(false); // cin.tie(0); // int n1, q1; // string a, b; // cin >> n1 >> q1 >> a >> b; // init(a, b); // cout << get_distance(2, 4); // }
#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...