Submission #1027662

#TimeUsernameProblemLanguageResultExecution timeMemory
1027662edogawa_somethingMutating DNA (IOI21_dna)C++17
100 / 100
32 ms12324 KiB
#include "dna.h"
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vii;
typedef pair<ll,ll> pii;
#define F first 
#define S second 
#define pb push_back
#define all(v) v.begin(),v.end()
const ll M=2e5+10;
const ll inf=2e18;
ll pre[M][3][3];
void init(string a,string b){
	for(int i=0;i<a.size();i++){
		ll x,y;
		if(a[i]=='C')
		x=0;
		if(a[i]=='T')
		x=1;
		if(a[i]=='A')
		x=2;
		if(b[i]=='C')
		y=0;
		if(b[i]=='T')
		y=1;
		if(b[i]=='A')
		y=2;
		pre[i+1][x][y]=1;
		for(int j=0;j<3;j++){
			for(int k=0;k<3;k++)
			pre[i+1][j][k]+=pre[i][j][k];
		}
	}
}

int get_distance(int x, int y) {
	ll cnt[3][3];
	y++;
	for(int i=0;i<3;i++)
	for(int j=0;j<3;j++)
	cnt[i][j]=pre[y][i][j]-pre[x][i][j];
	for(int i=0;i<3;i++){
		if(cnt[i][0]+cnt[i][1]+cnt[i][2]!=cnt[0][i]+cnt[1][i]+cnt[2][i])
		return -1;
	}
	ll ans=0;
	ll res=0;
	for(int i=0;i<3;i++){
		for(int j=i+1;j<3;j++){
			ll x=min(cnt[i][j],cnt[j][i]);
			res+=x;
			cnt[i][j]-=x,cnt[j][i]-=x;
		}
	}
	for(int i=0;i<3;i++){
		for(int j=0;j<3;j++)
		if(i!=j)
		ans+=cnt[i][j];
	}
	return res+(ans*2)/3;
}

Compilation message (stderr)

dna.cpp: In function 'void init(std::string, std::string)':
dna.cpp:15:15: 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=0;i<a.size();i++){
      |              ~^~~~~~~~~
dna.cpp:29:17: warning: 'y' may be used uninitialized in this function [-Wmaybe-uninitialized]
   29 |   pre[i+1][x][y]=1;
      |   ~~~~~~~~~~~~~~^~
dna.cpp:29:17: warning: 'x' may be used uninitialized in this function [-Wmaybe-uninitialized]
#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...