제출 #741966

#제출 시각아이디문제언어결과실행 시간메모리
741966EvirirDNA 돌연변이 (IOI21_dna)C++17
0 / 100
45 ms9164 KiB
#include "dna.h" #include <bits/stdc++.h> using namespace std; #define sz(x) (int)(x).size() #define all(x) begin(x), end(x) #define forn(i,a,b) for(int i=(a);i<(b);i++) #define fore(i,a,b) for(int i=(a);i<=(b);i++) #define pb push_back #define F first #define S second typedef long long ll; const ll INF = ll(1e18); const int MAXN = 100005; const unordered_map<string, int> smap{ {"AT", 0}, {"TA", 1}, {"AC", 2}, {"CA", 3}, {"TC", 4}, {"CT", 5}}; int n; string s,t; vector<vector<int>> pre; void init(string a, string b) { n = sz(a); s = a; t = b; pre.resize(n, vector<int>(6, 0)); forn(i,0,n) { string cur; cur.pb(s[i]); cur.pb(t[i]); if (s[i] == t[i]) continue; int id = smap.find(cur)->second; pre[i][id]++; if (i > 0) { forn(j,0,6) pre[i][j] += pre[i-1][j]; } } } vector<int> GetSum(int l, int r) { vector<int> res(6); forn(j,0,6) { res[j] = pre[r][j] - (l > 0 ? pre[l - 1][j] : 0); } return res; } int get_distance(int l, int r) { vector<int> cnt = GetSum(l, r); int ans = 0; for (int i = 0; i < 6; i += 2) { int c = min(cnt[i], cnt[i + 1]); ans += c; cnt[i] -= c; cnt[i + 1] -= c; } vector<int> v; for (const int x : cnt) if (x > 0) v.pb(x); if (!v.empty()) { if (sz(v) == 3 && v[0] == v[1] && v[1] == v[2]) { ans += v[0] * 2; } else { 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...