Submission #567440

#TimeUsernameProblemLanguageResultExecution timeMemory
567440losmi247Mutating DNA (IOI21_dna)C++17
100 / 100
66 ms10888 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; const int N = 1e5+23; int n; int a[N],b[N]; int pref[N][4][4]; void init(string s,string t){ n = s.size(); for(int i = 1; i <= n; i++){ if(s[i-1] == 'A') a[i] = 1; else if(s[i-1] == 'C') a[i] = 2; else a[i] = 3; if(t[i-1] == 'A') b[i] = 1; else if(t[i-1] == 'C') b[i] = 2; else b[i] = 3; } for(int h = 1; h <= n; h++){ for(int i = 1; i <= 3; i++){ for(int j = 1; j <= 3; j++){ pref[h][i][j] = pref[h-1][i][j]+(a[h] == i && b[h] == j); } } } } int sta[4][4]; int get_distance(int x,int y){ x++; y++; for(int i = 1; i <= 3; i++){ for(int j = 1; j <= 3; j++){ sta[i][j] = pref[y][i][j]-pref[x-1][i][j]; } } for(int i = 1; i <= 3; i++){ int s1 = 0; for(int j = 1; j <= 3; j++) s1 += sta[i][j]; int s2 = 0; for(int j = 1; j <= 3; j++) s2 += sta[j][i]; if(s1 != s2){ return -1; } } int v1 = min(sta[1][2],sta[2][1]); int v2 = min(sta[2][3],sta[3][2]); int v3 = min(sta[1][3],sta[3][1]); int dod = 2*abs(sta[1][2]-sta[2][1]); return v1+v2+v3+dod; }
#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...