Submission #438147

#TimeUsernameProblemLanguageResultExecution timeMemory
438147josiftepeMutating DNA (IOI21_dna)C++17
56 / 100
51 ms6316 KiB
#include <iostream> #include <vector> #include <algorithm> #include <cstring> #include "dna.h" using namespace std; const int maxn = 1e5 + 5; int a_pref_sum[maxn][4]; int b_pref_sum[maxn][4]; int pref_sum[maxn]; string a, b; vector<int> a_id[4], b_id[4]; int n; void init(string a, string b) { memset(a_pref_sum, 0, sizeof a_pref_sum); memset(b_pref_sum, 0, sizeof b_pref_sum); n = (int) a.size(); for(int i = 0; i < n; i++) { if(a[i] == 'C') a[i] = 'B'; if(b[i] == 'C') b[i] = 'B'; } for(int i = 0; i < n; i++) { if(a[i] == 'T') a[i] = 'C'; if(b[i] == 'T') b[i] = 'C'; } ::a = a; ::b = b; int cnt_a[3] = {0, 0, 0}; int cnt_b[3] = {0, 0, 0}; int sum = 0; for(int i = 0; i < n; i++) { int id_a = (int) (a[i] - 'A'); int id_b = (int) (b[i] - 'A'); cnt_a[id_a]++; cnt_b[id_b]++; for(int j = 0; j < 3; j++) { a_pref_sum[i][j] = cnt_a[j]; b_pref_sum[i][j] = cnt_b[j]; } if(a[i] != b[i]) { sum++; } pref_sum[i] = sum; } } int a_query(int &x, int &y, char c) { if(x == 0) { return a_pref_sum[y][c - 'A']; } return a_pref_sum[y][c - 'A'] - a_pref_sum[x - 1][c - 'A']; } int b_query(int &x, int &y, char c) { if(x == 0) { return b_pref_sum[y][c - 'A']; } return b_pref_sum[y][c - 'A'] - b_pref_sum[x - 1][c - 'A']; } int get_distance(int x, int y) { if(a_query(x, y, 'A') == b_query(x, y, 'A') and a_query(x, y, 'B') == b_query(x, y, 'B') and a_query(x, y, 'C') == b_query(x, y, 'C')) { if(x == 0) { return (pref_sum[y] + 1) / 2; } return (pref_sum[y] - pref_sum[x - 1] + 1) / 2; } return -1; }
#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...