제출 #823981

#제출 시각아이디문제언어결과실행 시간메모리
823981SoulKnightDNA 돌연변이 (IOI21_dna)C++17
56 / 100
263 ms5808 KiB
#include "dna.h" #include <bits/stdc++.h> using namespace std; #define ll long long #define ln '\n' const int N = 1e5 + 5; int same[N]; int n; vector<int> wa[3], wb[3]; map<string, vector<int>> mp; int get_range(const vector<int>& vec, int l, int r){ return upper_bound(vec.begin(), vec.end(), r) - lower_bound(vec.begin(), vec.end(), l); } void init(std::string a, std::string b) { n = a.size(); for (int i = 0; i < n; i++) same[i] = (a[i] == b[i]); for (int i = 0; i < n; i++) same[i] += same[i-1]; for (int i = 0; i < n; i++){ if (a[i] == 'A') wa[0].push_back(i); else if (a[i] == 'C') wa[1].push_back(i); else wa[2].push_back(i); } for (int i = 0; i < n; i++){ if (b[i] == 'A') wb[0].push_back(i); else if (b[i] == 'C') wb[1].push_back(i); else wb[2].push_back(i); } for (int i = 0; i < n; i++){ string s; s.append(1, a[i]); s.append(1, b[i]); mp[s].push_back(i); } } int get_distance(int x, int y) { bool ok = true; for (int i = 0; i < 3; i++){ int c1 = get_range(wa[i], x, y); int c2 = get_range(wb[i], x, y); if (c1 != c2) {ok = false; break;} } if (!ok) return -1; int len = y-x+1, ans = 0, res; res = min(get_range(mp["AC"], x, y), get_range(mp["CA"], x, y)); ans += res; len -= 2 * res; res = min(get_range(mp["AT"], x, y), get_range(mp["TA"], x, y)); ans += res; len -= 2 * res; res = min(get_range(mp["CT"], x, y), get_range(mp["TC"], x, y)); ans += res; len -= 2 * res; int s = (same[y] - ((x-1 < 0)? 0: same[x-1])); return max(0, len - s - 1) + 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...