제출 #483884

#제출 시각아이디문제언어결과실행 시간메모리
483884dnauxDNA 돌연변이 (IOI21_dna)C++17
35 / 100
42 ms7208 KiB
#include <bits/stdc++.h> #define endline "\n" #define pb push_back #define mp make_pair #define st first #define nd second #define lsb(i) i&(-i) #define sz(i) (int)i.size() typedef long long ll; using namespace std; const ll INF = 1e18L; constexpr int mod = int(1e9) + 7; ll t=1, n, q, k, cases = 0; string a, b; vector<array<int,3>> coua,coub; // 0 = A, 1 = T, 2 = C vector<array<int,6>> diff; // 0 = TA, 1 = AT, 2 = CA, 3 = AC, 4 = TC, 5 = CT void init(string a, string b){ n = sz(a); coua.resize(n);coub.resize(n);diff.resize(n); for(int i = 0; i < n; i++){ if(i){ for(int j = 0; j < 3; j++){ coua[i][j] = coua[i - 1][j]; coub[i][j] = coub[i - 1][j]; } } int xa = a[i] == 'A' ? 0 : (a[i] == 'T' ? 1 : 2); coua[i][xa]++; int xb = b[i] == 'A' ? 0 : (b[i] == 'T' ? 1 : 2); coub[i][xb]++; } for(int i = 0; i < n; i++){ if(i){ for(int j = 0; j < 6; j++){ diff[i][j] = diff[i - 1][j]; } } if(a[i] == 'T'){ if(b[i] == 'A')diff[i][0]++; else if(b[i] == 'C')diff[i][4]++; } else if(a[i] == 'A'){ if(b[i] == 'T')diff[i][1]++; else if(b[i] == 'C')diff[i][3]++; } else{ if(b[i] == 'A')diff[i][2]++; else if(b[i] == 'T')diff[i][5]++; } } } int get_distance(int x, int y){ if(!x){ if(coua[y][0] != coub[y][0] or coua[y][1] != coub[y][1] or coua[y][2] != coub[y][2])return -1; } else{ if(coua[y][0] - coua[x - 1][0] != coub[y][0] - coub[x - 1][0]){ return -1; } else if(coua[y][1] - coua[x - 1][1] != coub[y][1] - coub[x - 1][1]){ return -1; } else if(coua[y][2] - coua[x - 1][2] != coub[y][2] - coub[x - 1][2]){ return -1; } } ll ans = 0, bruh = 0; if(!x){ ans += min(diff[y][0], diff[y][1]); bruh += abs(diff[y][0] - diff[y][1]); } else{ ans += min(diff[y][0] - diff[x - 1][0], diff[y][1] - diff[x - 1][1]); bruh += abs((diff[y][0] - diff[x - 1][0]) - (diff[y][1] - diff[x - 1][1])); } if(!x){ ans += min(diff[y][2], diff[y][3]); bruh += abs(diff[y][2] - diff[y][3]); } else{ ans += min(diff[y][2] - diff[x - 1][2], diff[y][3] - diff[x - 1][3]); bruh += abs((diff[y][2] - diff[x - 1][2]) - (diff[y][3] - diff[x - 1][3])); } if(!x){ ans += min(diff[y][4], diff[y][5]); bruh += abs(diff[y][4] - diff[y][5]); } else{ ans += min(diff[y][4] - diff[x - 1][4], diff[y][5] - diff[x - 1][5]) / 2; bruh += abs((diff[y][4] - diff[x - 1][4]) - (diff[y][5] - diff[x - 1][5])); } ans += (bruh / 3) * 2; return ans; } /*int main(){ #ifdef local freopen("trie.gir","r",stdin); freopen("trie.cik","w",stdout); #endif ios_base::sync_with_stdio(false);cin.tie(NULL); //cin>>t; //for(; cases <= t; cases++)solve(); cin >> n >> q; cin >> a >> b; init(a, b); for(int i = 0; i < q; i++){ int x, y; cin >> x >> y; cout << get_distance(x, y) << endline; } return 0; }*/
#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...