Submission #955585

#TimeUsernameProblemLanguageResultExecution timeMemory
955585steveonalexMutating DNA (IOI21_dna)C++17
100 / 100
34 ms8468 KiB
#include <bits/stdc++.h> #include "dna.h" using namespace std; typedef long long ll; typedef unsigned long long ull; #define MASK(i) (1ULL << (i)) #define GETBIT(mask, i) (((mask) >> (i)) & 1) #define ALL(v) (v).begin(), (v).end() ll max(ll a, ll b){return (a > b) ? a : b;} ll min(ll a, ll b){return (a < b) ? a : b;} ll LASTBIT(ll mask){return (mask) & (-mask);} int pop_cnt(ll mask){return __builtin_popcountll(mask);} int ctz(ull mask){return __builtin_ctzll(mask);} int logOf(ull mask){return 63 - __builtin_clzll(mask);} mt19937_64 rng(chrono::high_resolution_clock::now().time_since_epoch().count()); ll rngesus(ll l, ll r){return l + (ull) rng() % (r - l + 1);} template <class T1, class T2> bool maximize(T1 &a, T2 b){ if (a < b) {a = b; return true;} return false; } template <class T1, class T2> bool minimize(T1 &a, T2 b){ if (a > b) {a = b; return true;} return false; } template <class T> void printArr(T& container, string separator = " ", string finish = "\n", ostream &out = cout){ for(auto item: container) out << item << separator; out << finish; } template <class T> void remove_dup(vector<T> &a){ sort(ALL(a)); a.resize(unique(ALL(a)) - a.begin()); } int convert(char c){ if (c == 'A') return 0; if (c == 'T') return 1; if (c == 'C') return 2; return 3; } const int N = 1e5 + 69; int n; int cnt[N][3]; int cnt_pair[N][3][3]; void init(string a, string b){ n = a.size(); for(int i = 1; i<=n; ++i){ for(int j = 0; j<3; ++j) cnt[i][j] = cnt[i-1][j]; cnt[i][convert(a[i-1])]++; cnt[i][convert(b[i-1])]--; for(int x = 0; x < 3; ++x) for(int y = 0; y < 3; ++y) cnt_pair[i][x][y] = cnt_pair[i-1][x][y]; cnt_pair[i][convert(a[i-1])][convert(b[i-1])]++; } } int get_distance(int l, int r){ l++; r++; for(int x = 0; x< 3; ++x) if (cnt[r][x] - cnt[l-1][x] != 0) return -1; int graph[3][3]; memset(graph, 0, sizeof graph); for(int x = 0; x < 3; ++x) for(int y = 0; y < 3; ++y) graph[x][y] = cnt_pair[r][x][y] - cnt_pair[l-1][x][y]; int ans = 0; for(int x = 0; x < 3; ++x) for(int y = x + 1; y < 3; ++y) { int cur = min(graph[x][y], graph[y][x]); ans += cur; graph[x][y] -= cur; graph[y][x] -= cur; } for(int x = 0; x < 3; ++x) for(int y = 0; y < 3; ++y) if (y != x){ int z = 3 - x - y; if (x == 0 || y == 1 || z == 2) continue; int cur = min({graph[0][x], graph[1][y], graph[2][z]}); ans += cur * 2; graph[0][x] -= cur; graph[1][y] -= cur; graph[2][z] -= cur; } return ans; } // int main(void){ // ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); // init("ATAC", "ACAT"); // cout << get_distance(1, 3) << "\n"; // return 0; // }
#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...