Submission #852871

#TimeUsernameProblemLanguageResultExecution timeMemory
852871hngwlogMutating DNA (IOI21_dna)C++17
35 / 100
85 ms22496 KiB
#include <bits/stdc++.h> #include "dna.h" using namespace std; #define fi first #define se second #define _size(x) (int)x.size() #define BIT(i, x) ((x >> i) & 1) #define MASK(n) ((1 << n) - 1) #define REP(i, n) for (int i = 0, _n = (n); i < _n; i++) #define FOR(i, a, b) for (int i = a, _b = (b); i <= _b; i++) #define FORD(i, a, b) for (int i = a, _b = (b); i >= _b; i--) #define FORB1(i, mask) for (int i = mask; i > 0; i ^= i & - i) #define FORB0(i, n, mask) for (int i = ((1 << n) - 1) ^ mask; i > 0; i ^= i & - i) #define FORALL(i, a) for (auto i: a) #define fastio ios_base::sync_with_stdio(0); cin.tie(0); vector<vector<vector<int>>> f; void init(string a, string b) { int n = _size(a); vector<int> chA(n + 1), chB(n + 1); f.resize(n + 1, vector<vector<int>>(3, vector<int>(3))); FOR(i, 1, n) { if (a[i - 1] == 'A') chA[i] = 0; else if (a[i - 1] == 'T') chA[i] = 1; else chA[i] = 2; if (b[i - 1] == 'A') chB[i] = 0; else if (b[i - 1] == 'T') chB[i] = 1; else chB[i] = 2; REP(j, 3) REP(z, 3) f[i][j][z] = f[i - 1][j][z]; f[i][chA[i]][chB[i]]++; } } int get_distance(int x, int y) { x++, y++; vector<vector<int>> g(3, vector<int>(3)); REP(i, 3) REP(j, 3) g[i][j] = f[y][i][j] - f[x - 1][i][j]; int ans = 0; REP(i, 3) REP(j, 3) { int value = min(g[i][j], g[j][i]); g[i][j] -= value; if (i == j) continue; g[j][i] -= value; ans += value; } vector<pair<int, int>> vtx; REP(i, 3) REP(j, 3) if (g[i][j]) vtx.push_back({i, j}); if (!_size(vtx)) return ans; if (_size(vtx) != 3) return - 1; int value = g[vtx[0].fi][vtx[0].se]; FORALL(e, vtx) if (g[e.fi][e.se] != value) return - 1; FORALL(p, vtx) FORALL(q, vtx) { if (p == q) continue; int cnt = (p.fi == q.fi) + (p.fi == q.se) + (p.se == q.fi) + (p.se == q.se); if (cnt != 1) return - 1; } return ans + value * 2; }
#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...