Submission #483877

#TimeUsernameProblemLanguageResultExecution timeMemory
483877dnauxMutating DNA (IOI21_dna)C++17
56 / 100
41 ms6272 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<int> diff; 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){ diff[i] = diff[i - 1]; } if(a[i] != b[i])diff[i]++; } } 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; } } if(!x){ return diff[y] / 2 + (diff[y] % 2); } else{ return (diff[y] - diff[x - 1]) / 2 + ((diff[y] - diff[x - 1]) % 2); } } /*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...