Submission #439840

#TimeUsernameProblemLanguageResultExecution timeMemory
439840adamjinweiMutating DNA (IOI21_dna)C++17
0 / 100
55 ms9588 KiB
#include <bits/stdc++.h> #include "dna.h" #define inf 1000000007 #define mod 1000000007 #define rnd() rand_num() #define bigrnd() dis(rand_num) //#pragma GCC optimize("Ofast","inline","-ffast-math") //#pragma GCC target("avx,sse2,sse3,sse4,mmx") //#define int long long using namespace std; unsigned sed=std::chrono::system_clock::now().time_since_epoch().count(); mt19937 rand_num(sed); uniform_int_distribution<long long> dis(0,inf); template <typename T> void read(T &x){ x=0;char ch=getchar();int fh=1; while (ch<'0'||ch>'9'){if (ch=='-')fh=-1;ch=getchar();} while (ch>='0'&&ch<='9')x=x*10+ch-'0',ch=getchar(); x*=fh; } template <typename T> void write(T x) { if (x<0) x=-x,putchar('-'); if (x>9) write(x/10); putchar(x%10+'0'); } template <typename T> void writeln(T x) { write(x); puts(""); } int n; char a[100005],b[100005]; int cnta[3][100005]; int cntb[3][100005]; int cnt[10][100005]; inline int get(char x,char y) { if(x=='A') { if(y=='A') return 1; else if(y=='T') return 2; else return 3; } else if(x=='T') { if(y=='A') return 4; else if(y=='T') return 5; else return 6; } else { if(y=='A') return 7; else if(y=='T') return 8; else return 9; } } void init(string A,string B) { n=A.size(); for(int i=1;i<=n;++i) { a[i]=A[i-1]; b[i]=B[i-1]; } for(int i=1;i<=n;++i) { cnta[0][i]=cnta[0][i-1]+(a[i]=='A'?1:0); cnta[1][i]=cnta[1][i-1]+(a[i]=='T'?1:0); cnta[2][i]=cnta[2][i-1]+(a[i]=='C'?1:0); cntb[0][i]=cntb[0][i-1]+(b[i]=='A'?1:0); cntb[1][i]=cntb[1][i-1]+(b[i]=='T'?1:0); cntb[2][i]=cntb[2][i-1]+(b[i]=='C'?1:0); for(int j=1;j<=9;++j) if(j==get(a[i],b[i])) cnt[j][i]=cnt[j][i-1]+1; else cnt[j][i]=cnt[j][i-1]; } } int get_distance(int x,int y) { x++,y++; if(cnta[0][y]-cnta[0][x-1]!=cntb[0][y]-cntb[0][x-1]) return -1; if(cnta[1][y]-cnta[1][x-1]!=cntb[1][y]-cntb[1][x-1]) return -1; if(cnta[2][y]-cnta[2][x-1]!=cntb[2][y]-cntb[2][x-1]) return -1; int ans=y-x+1,cur=y-x+1; ans-=cnt[1][y]-cnt[1][x-1]; ans-=cnt[5][y]-cnt[5][x-1]; ans-=cnt[9][y]-cnt[9][y-1]; ans-=min(cnt[2][y]-cnt[2][x-1],cnt[4][y]-cnt[4][x-1]); ans-=min(cnt[3][y]-cnt[3][x-1],cnt[7][y]-cnt[7][x-1]); ans-=min(cnt[6][y]-cnt[6][x-1],cnt[8][y]-cnt[8][x-1]); cur-=2*min(cnt[2][y]-cnt[2][x-1],cnt[4][y]-cnt[4][x-1]); cur-=2*min(cnt[3][y]-cnt[3][x-1],cnt[7][y]-cnt[7][x-1]); cur-=2*min(cnt[6][y]-cnt[6][x-1],cnt[8][y]-cnt[8][x-1]); ans-=cur/3; return ans; }
#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...