Submission #437075

# Submission time Handle Problem Language Result Execution time Memory
437075 2021-06-25T18:36:01 Z T0p_ Mutating DNA (IOI21_dna) C++17
Compilation error
0 ms 0 KB
#include "dna.h"
#include <bits/stdc++.h>
using namespace std;

void init(string a, string b)
{
	n = a.length();
	mp['A'] = 0;
	mp['C'] = 1;
	mp['T'] = 2;

	cnt[0][mp[a[0]]][1]++;
	cnt[1][mp[b[0]]][1]++;
	ans[1] = (a[0] == b[0]) ? 0 : 1;

	for(int i=2 ; i<=n ; i++)
	{
		cnt[0][mp[a[i-1]]][i]++;
		cnt[1][mp[b[i-1]]][i]++;
		for(int j=0 ; j<3 ; j++)
		{
			cnt[0][j][i] += cnt[0][j][i-1];
			cnt[1][j][i] += cnt[1][j][i-1];
		}
		ans[i] = ans[i-1] + ((a[i-1] == b[i-1]) ? 0 : 1);
	}
}

int get_distance(int x, int y)
{
	x++, y++;
	for(int j=0 ; j<3 ; j++) if(cnt[0][j][y]-cnt[0][j][x-1] != cnt[1][j][y]-cnt[1][j][x-1]) return -1;
	int ret = 0;
	int dif = ans[y] - ans[x-1];
	if(dif%2)
	{
		ret += 2;
		dif -= 3;
	}
	ret += dif/2;
	return ret;
}

Compilation message

dna.cpp: In function 'void init(std::string, std::string)':
dna.cpp:7:2: error: 'n' was not declared in this scope
    7 |  n = a.length();
      |  ^
dna.cpp:8:2: error: 'mp' was not declared in this scope
    8 |  mp['A'] = 0;
      |  ^~
dna.cpp:12:2: error: 'cnt' was not declared in this scope; did you mean 'int'?
   12 |  cnt[0][mp[a[0]]][1]++;
      |  ^~~
      |  int
dna.cpp:14:2: error: 'ans' was not declared in this scope; did you mean 'abs'?
   14 |  ans[1] = (a[0] == b[0]) ? 0 : 1;
      |  ^~~
      |  abs
dna.cpp: In function 'int get_distance(int, int)':
dna.cpp:32:30: error: 'cnt' was not declared in this scope; did you mean 'int'?
   32 |  for(int j=0 ; j<3 ; j++) if(cnt[0][j][y]-cnt[0][j][x-1] != cnt[1][j][y]-cnt[1][j][x-1]) return -1;
      |                              ^~~
      |                              int
dna.cpp:34:12: error: 'ans' was not declared in this scope; did you mean 'abs'?
   34 |  int dif = ans[y] - ans[x-1];
      |            ^~~
      |            abs