Submission #630821

#TimeUsernameProblemLanguageResultExecution timeMemory
630821tmncollinsMutating DNA (IOI21_dna)C++17
100 / 100
39 ms10892 KiB
#include "dna.h" #include <stdio.h> #include <vector> #include <string> #include <map> #include <iostream> #include <cmath> #include <algorithm> // g++ grader.cpp dna.cpp -o dna using namespace std; map<char, int> base; struct pref { int arr[3][3], copy[3][3]; pref() { for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { arr[i][j] = copy[i][j] = 0; } } } void add(pref p) { for (int a = 0; a < 3; a++) { for (int b = 0; b < 3; b++) { arr[a][b] += p.arr[a][b]; } } } void subt(pref p) { for (int a = 0; a < 3; a++) { for (int b = 0; b < 3; b++) { arr[a][b] -= p.arr[a][b]; } } } int dist() { int d = 0; for (int i = 0; i < 3; i++) { int a = 0, b = 0; for (int j = 0; j < 3; j++) { copy[i][j] = arr[i][j]; a += arr[i][j]; b += arr[j][i]; } if (a != b) return -1; } int unpaired = 0; // directly swap a and b for (int a = 0; a < 3; a++) { for (int b = 0; b < a; b++) { int v = min(arr[a][b], arr[b][a]); copy[a][b] -= v; copy[b][a] -= v; d += v; unpaired += copy[a][b] + copy[b][a]; } } unpaired /= 3; unpaired *= 2; return d + unpaired; } void output() { cout << "==========\n"; for (int k = 0; k < 3; k++) { for (int i = 0; i < 3; i++) cout << arr[k][i] << " "; cout << "\n"; } cout << "==========\n"; } }; vector<pref> prefix; void init(string a, string b) { int size = a.size() + 1; prefix = vector<pref> (size); base['A'] = 0; base['C'] = 1; base['T'] = 2; prefix[0] = pref(); // A, C, T (1), A, C, T (2), diff for (int k = 1; k < size; k++) { int i = k-1; prefix[k] = prefix[k-1]; int base_a = base[a[i]]; int base_b = base[b[i]]; prefix[k].arr[base_a][base_b]++; // prefix[k].arr[base_b][base_a]++; } } int get_distance(int x, int y) { pref a = prefix[x], b = prefix[y+1]; b.subt(a); // b.output(); return b.dist(); } /* */
#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...