Submission #437096

#TimeUsernameProblemLanguageResultExecution timeMemory
437096xiaowuc1Mutating DNA (IOI21_dna)C++17
100 / 100
58 ms6048 KiB
#include <algorithm> #include <array> #include <bitset> #include <cassert> #include <chrono> #include <cstring> #include <iomanip> #include <iostream> #include <map> #include <queue> #include <random> #include <set> #include <stack> #include <vector> using namespace std; // BEGIN NO SAD #define rep(i, a, b) for(int i = a; i < (b); ++i) #define trav(a, x) for(auto& a : x) #define all(x) x.begin(), x.end() #define sz(x) (int)(x).size() #define mp make_pair #define pb push_back #define eb emplace_back #define lb lower_bound #define ub upper_bound typedef vector<int> vi; #define f first #define s second // END NO SAD typedef long long ll; typedef pair<int, int> pii; typedef pair<ll, ll> pll; typedef vector<vector<ll>> matrix; int dp[6][100005]; int cnt[3][100005]; void init(string a, string b) { int n = sz(a); for(int i = 0; i < n; i++) { for(int j = 0; j < 3; j++) { cnt[j][i+1] = cnt[j][i]; } if(a[i] == 'A') cnt[0][i+1]++; if(b[i] == 'A') cnt[0][i+1]--; if(a[i] == 'C') cnt[1][i+1]++; if(b[i] == 'C') cnt[1][i+1]--; if(a[i] == 'T') cnt[2][i+1]++; if(b[i] == 'T') cnt[2][i+1]--; } for(int i = 0; i < n; i++) { for(int j = 0; j < 6; j++) { dp[j][i+1] = dp[j][i]; } if(a[i] == 'A' && b[i] == 'C') dp[0][i+1]++; if(a[i] == 'C' && b[i] == 'A') dp[1][i+1]++; if(a[i] == 'A' && b[i] == 'T') dp[2][i+1]++; if(a[i] == 'T' && b[i] == 'A') dp[3][i+1]++; if(a[i] == 'C' && b[i] == 'T') dp[4][i+1]++; if(a[i] == 'T' && b[i] == 'C') dp[5][i+1]++; } } int get_distance(int a, int b) { b++; if(cnt[0][b] != cnt[0][a]) return -1; if(cnt[1][b] != cnt[1][a]) return -1; if(cnt[2][b] != cnt[2][a]) return -1; int ret = 0; int tot = 0; for(int i = 0; i < 6; i++) { tot += dp[i][b] - dp[i][a]; } for(int i = 0; i < 6; i += 2) { int use = min(dp[i][b] - dp[i][a], dp[i+1][b] - dp[i+1][a]); tot -= 2 * use; ret += use; } assert(tot % 3 == 0); ret += (tot / 3) * 2; return ret; } /* void solve() { } // what would chika do // are there edge cases (N=1?) // are array sizes proper (scaled by proper constant, for example 2* for koosaga tree) // integer overflow? // DS reset properly between test cases // are you doing geometry in floating points int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); solve(); } */
#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...