Submission #1102595

#TimeUsernameProblemLanguageResultExecution timeMemory
1102595KasymKMutating DNA (IOI21_dna)C++17
0 / 100
25 ms6996 KiB
#include "bits/stdc++.h" using namespace std; #define ff first #define ss second #define all(v) v.begin(), v.end() #define ll long long #define pb push_back #define pii pair<int, int> #define pli pair<ll, int> #define pll pair<ll, ll> #define tr(i, c) for(auto i = c.begin(); i != c.end(); ++i) #define wr puts("----------------") template<class T>bool umin(T& a,T b){if(a>b){a=b;return 1;}return 0;} template<class T>bool umax(T& a,T b){if(a<b){a=b;return 1;}return 0;} const int N = 1e5+5; string s, s2; int par[N], par0[N], cnt[N][3], cnt0[N][3]; char dodge[] = {'A', 'C', 'T'}; void init(string a, string b){ s = "!", s2 = "!"; int n = (int)a.size(); for(int i = 0; i < n; ++i) s += a[i], s2 += b[i]; // wr; // cout<<s<<"\n"<<s2<<"\n"; // wr; for(int i = 1; i <= n; ++i) for(int j = 0; j < 3; ++j){ cnt[i][j] = cnt[i-1][j], cnt0[i][j] = cnt0[i-1][j]; if(dodge[j] == s[i]) cnt[i][j]++; if(dodge[j] == s2[i]) cnt0[i][j]++; } // for(int i = 1; i <= n; ++i){ // for(int j = 0; j < 3; ++j) // printf("%d ", cnt[i][j]); // puts(""); // } for(int i = 1; i <= n; ++i){ par[i] = par[i-1]+(s[i]=='A' and s2[i]!='A')+(s[i]=='T' and s2[i]=='C'); par0[i] = par0[i-1]+(s[i]=='A' and s2[i]=='C')-(s[i]=='C' and s2[i]=='A'); } } int get_distance(int l, int r){ bool did = 1; for(int i = 0; i < 3 and did; ++i) if(cnt[r][i]-cnt[l-1][i] != cnt0[r][i]-cnt0[l-1][i]) did = 0; if(!did) return -1; int answer = par[r]-par[l-1]+max(par0[r]-par0[l-1], 0); return answer; } // int main(){ // freopen("file.txt", "r", stdin); // int q; // scanf("%d", &q); // string a, b; // cin >> a >> b; // init(a, b); // while(q--){ // int l, r; // scanf("%d%d", &l, &r), l++, r++; // printf("%d\n", get_distance(l, r)); // } // 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...