# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
454588 | ogibogi2004 | Mutating DNA (IOI21_dna) | C++17 | 83 ms | 11052 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include "dna.h"
#include <bits/stdc++.h>
using namespace std;
const int MAXN=1e5+6;
int prcnt[MAXN][4][4];
int prcnt1[MAXN][4];
void init(string a, string b) {
for(int i=1;i<=a.size();i++)
{
for(int j1=0;j1<4;j1++)
{
for(int j2=0;j2<4;j2++)
{
prcnt[i][j1][j2]=prcnt[i-1][j1][j2];
}
prcnt1[i][j1]=prcnt1[i-1][j1];
}
int c1=0,c2=0;
if(a[i-1]=='A')c1=1;
if(a[i-1]=='C')c1=2;
if(a[i-1]=='T')c1=3;
if(b[i-1]=='A')c2=1;
if(b[i-1]=='C')c2=2;
if(b[i-1]=='T')c2=3;
prcnt[i][c1][c2]++;
prcnt1[i][c1]++;
prcnt1[i][c2]--;
}
}
int get_distance(int x, int y) {
x++;y++;
int cnt[4][4];
for(int j1=0;j1<4;j1++)
{
for(int j2=0;j2<4;j2++)
{
cnt[j1][j2]=prcnt[y][j1][j2]-prcnt[x-1][j1][j2];
}
}
//cout<<"*\n";
int cntswaps=0;
for(int j=0;j<4;j++)
{
if(prcnt1[y][j]-prcnt1[x-1][j]!=0)return -1;
}
for(int j1=0;j1<4;j1++)
{
for(int j2=0;j2<4;j2++)
{
if(j1==j2)continue;
cntswaps+=cnt[j1][j2];
}
}
for(int j1=1;j1<4;j1++)
{
for(int j2=j1+1;j2<4;j2++)
{
int t=min(cnt[j1][j2],cnt[j2][j1]);
cnt[j1][j2]-=t;cnt[j2][j1]-=t;
cntswaps-=t;
}
}
int cnt1=0;
set<int>s;
for(int j1=1;j1<4;j1++)
{
for(int j2=1;j2<4;j2++)
{
if(j1==j2)continue;
if(cnt[j1][j2]>0)
{
s.insert(cnt[j1][j2]);
cnt1++;
}
}
}
if(cnt1==0)return cntswaps;
//cout<<s.size()<<endl;
if(s.size()!=1)assert(false);
return cntswaps-(*s.begin());
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |