제출 #735784

#제출 시각아이디문제언어결과실행 시간메모리
735784NatInTheHatDNA 돌연변이 (IOI21_dna)C++17
35 / 100
50 ms7700 KiB
#include <bits/stdc++.h> using namespace std; #define rep(i, a, b) for(int i = a; i < (b); ++i) #define all(x) begin(x), end(x) #define sz(x) (int)(x).size() typedef long long ll; typedef long double ld; typedef pair<int, int> pii; typedef vector<int> vi; template<class T, class U> istream& operator>>(istream &is, pair<T, U>& p) { is >> p.first >> p.second; return is; } template<class T> istream& operator>>(istream& is, vector<T>& vec) { for(auto &x : vec) cin >> x; return is; } template<class T, class U> ostream& operator<<(ostream &os, pair<T, U>& p) { os << "<" << p.first << "," << p.second << ">"; return os; } template<class T> ostream& operator<<(ostream& os, vector<T>& vec) { for(auto x : vec) os << x << " "; return os; } int conv(char c) { if (c == 'A') return 0; else if (c == 'C') return 1; return 2; } const int TYPES = 9, MAXN = 100010; int prefs[TYPES][MAXN]; int n; void init(string sa, string sb) { n = sa.size(); vector<int> a(n), b(n); for (int i = 0; i < n; i++) { a[i] = conv(sa[i]); b[i] = conv(sb[i]); } for (int i = 0; i < n; i++) { int type = a[i] * 3 + b[i]; prefs[type][i]++; if (i > 0) { for (int t = 0; t < TYPES; t++) { prefs[t][i] += prefs[t][i-1]; } } } } int get_sum(int type, int l, int r) { if (l == 0) return prefs[type][r]; return prefs[type][r] - prefs[type][l-1]; } int get_distance(int l, int r) { vector<int> type_sums(TYPES); for (int t = 0; t < TYPES; t++) { type_sums[t] = get_sum(t, l, r); } int swaps = 0; // cancel out on diagonal. swaps += min(type_sums[1], type_sums[3]); swaps += min(type_sums[2], type_sums[6]); swaps += min(type_sums[5], type_sums[7]); vector<int> rems = { abs(type_sums[1] - type_sums[3]), abs(type_sums[2] - type_sums[6]), abs(type_sums[5] - type_sums[7]) }; if (rems[0] == rems[1] && rems[1] == rems[2]) { swaps += rems[0] * 2; return swaps; } else return -1; }
#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...