Submission #524673

#TimeUsernameProblemLanguageResultExecution timeMemory
524673LoboMutating DNA (IOI21_dna)C++17
100 / 100
50 ms10496 KiB
#include "dna.h" #include<bits/stdc++.h> using namespace std; const long long inf = (long long) 1e18 + 10; const int inf1 = (int) 1e9 + 10; // #define int long long #define dbl long double #define endl '\n' #define sc second #define fr first #define mp make_pair #define pb push_back #define all(x) x.begin(), x.end() #define maxn 110000 int v1[maxn], v2[maxn], qtd1[3][maxn], qtd2[3][maxn], ans[maxn][3][3]; int get_distance(int x, int y) { int l = x+1; int r = y+1; if(qtd1[0][r]-qtd1[0][l-1] != qtd2[0][r]-qtd2[0][l-1] || qtd1[1][r]-qtd1[1][l-1] != qtd2[1][r]-qtd2[1][l-1] || qtd1[2][r]-qtd1[2][l-1] != qtd2[2][r]-qtd2[2][l-1]) { return -1; } int ans1 = 0; int ok = 0; for(int i = 0; i <= 2; i++) { for(int j = 0; j <= 2; j++) { if(i == j) continue; if(ans[r][i][j]-ans[l-1][i][j] == ans[r][j][i]-ans[l-1][j][i]) { ans1+= ans[r][i][j]-ans[l-1][i][j]; } else { ok+= max(ans[r][i][j]-ans[l-1][i][j],ans[r][j][i]-ans[l-1][j][i]) - min(ans[r][i][j]-ans[l-1][i][j],ans[r][j][i]-ans[l-1][j][i]); ans1+= min(ans[r][i][j]-ans[l-1][i][j],ans[r][j][i]-ans[l-1][j][i]); } } } return ans1/2+(ok)/3; } void init(string a, string b) { int n = a.size(); for(int i = 1; i <= n; i++) { if(a[i-1] == 'A') v1[i] = 0; if(a[i-1] == 'T') v1[i] = 1; if(a[i-1] == 'C') v1[i] = 2; qtd1[0][i] = qtd1[0][i-1]; qtd1[1][i] = qtd1[1][i-1]; qtd1[2][i] = qtd1[2][i-1]; qtd1[v1[i]][i]++; } for(int i = 1; i <= n; i++) { if(b[i-1] == 'A') v2[i] = 0; if(b[i-1] == 'T') v2[i] = 1; if(b[i-1] == 'C') v2[i] = 2; qtd2[0][i] = qtd2[0][i-1]; qtd2[1][i] = qtd2[1][i-1]; qtd2[2][i] = qtd2[2][i-1]; qtd2[v2[i]][i]++; } for(int i = 1; i <= n; i++) { for(int p1 = 0; p1 <= 2; p1++) { for(int p2 = 0; p2 <= 2; p2++) { ans[i][p1][p2] = ans[i-1][p1][p2]; } } ans[i][v1[i]][v2[i]]++; } }
#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...