Submission #917935

#TimeUsernameProblemLanguageResultExecution timeMemory
917935tnunMutating DNA (IOI21_dna)C++17
100 / 100
30 ms6332 KiB
#include <bits/stdc++.h>; using namespace std; #define ll long long #define pb push_back const int maxn=100006; int CA[maxn]={0}; int AC[maxn]={0}; int TA[maxn]={0}; int AT[maxn]={0}; int TC[maxn]={0}; int CT[maxn]={0}; void init(string a,string b){ string a1="P"+a; string b1="P"+b; for(int i=1;i<=a.length();i++){ CA[i]=CA[i-1]; TA[i]=TA[i-1]; CT[i]=CT[i-1]; TC[i]=TC[i-1]; AT[i]=AT[i-1]; AC[i]=AC[i-1]; if(a1[i]=='A' && b1[i]=='C'){ AC[i]++; } if(a1[i]=='T' && b1[i]=='C'){ TC[i]++; } if(a1[i]=='A' && b1[i]=='T'){ AT[i]++; } if(a1[i]=='T' && b1[i]=='A'){ TA[i]++; } if(a1[i]=='C' && b1[i]=='T'){ CT[i]++; } if(a1[i]=='C' && b1[i]=='A'){ CA[i]++; } } } int get_distance(int x,int y){ x++; y++; int sum=0; int ca1=CA[y]-CA[x-1]; int ac1=AC[y]-AC[x-1]; int ta1=TA[y]-TA[x-1]; int at1=AT[y]-AT[x-1]; int ct1=CT[y]-CT[x-1]; int tc1=TC[y]-TC[x-1]; int temp=min(ca1,ac1); ca1-=temp; ac1-=temp; sum+=temp; temp=min(ta1,at1); ta1-=temp; at1-=temp; sum+=temp; temp=min(tc1,ct1); tc1-=temp; ct1-=temp; sum+=temp; temp=min(tc1,min(ca1,at1)); sum+=temp*2; tc1-=temp; ca1-=temp; at1-=temp; temp=min(ta1,min(ac1,ct1)); sum+=temp*2; ta1-=temp; ac1-=temp; ct1-=temp; if(ta1!=0 || at1!=0 || tc1!=0 || ct1!=0 || ac1!=0 || ca1!=0){ return -1; }else{ return sum; } }

Compilation message (stderr)

dna.cpp:1:25: warning: extra tokens at end of #include directive
    1 | #include <bits/stdc++.h>;
      |                         ^
dna.cpp: In function 'void init(std::string, std::string)':
dna.cpp:15:14: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   15 | for(int i=1;i<=a.length();i++){
      |             ~^~~~~~~~~~~~
#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...