Submission #483897

#TimeUsernameProblemLanguageResultExecution timeMemory
483897dnauxMutating DNA (IOI21_dna)C++17
100 / 100
56 ms8552 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 + 1);coub.resize(n + 1);diff.resize(n + 1); for(int i = 1; i <= n; 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 - 1] == 'A' ? 0 : (a[i - 1] == 'T' ? 1 : 2); coua[i][xa]++; int xb = b[i - 1] == 'A' ? 0 : (b[i - 1] == 'T' ? 1 : 2); coub[i][xb]++; } for(int i = 1; i <= n; i++){ for(int j = 0; j < 6; j++){ diff[i][j] = diff[i - 1][j]; } if(a[i - 1] == 'T'){ if(b[i - 1] == 'A')diff[i][0]++; else if(b[i - 1] == 'C')diff[i][4]++; } else if(a[i - 1] == 'A'){ if(b[i - 1] == 'T')diff[i][1]++; else if(b[i - 1] == 'C')diff[i][3]++; } else{ if(b[i - 1] == 'A')diff[i][2]++; else if(b[i - 1] == 'T')diff[i][5]++; } } } int get_distance(int x, int y){ x++;y++; 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; 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])); //cout << ans << '/'; 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])); //cout << ans << '/'; ans += min(diff[y][4] - diff[x - 1][4], diff[y][5] - diff[x - 1][5]); bruh += abs((diff[y][4] - diff[x - 1][4]) - (diff[y][5] - diff[x - 1][5])); //cout << diff[y][4] << " " << diff[x - 1][4] << " " << diff[y][5] << " " << diff[x - 1][5] << endline; 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...