Submission #579832

#TimeUsernameProblemLanguageResultExecution timeMemory
579832joelauMutating DNA (IOI21_dna)C++17
100 / 100
47 ms7412 KiB
#include "dna.h"
#include <bits/stdc++.h>
using namespace std;

int A[100005][3][3];

void init(string a, string b) {
	for (int i = 0; i < 3; ++i) for (int j = 0; j < 3; ++j) A[0][i][j] = 0;
	for (int i = 0; i < a.length(); ++i) {
		for (int j = 0; j < 3; ++j) for (int k = 0; k < 3; ++k) A[i+1][j][k] = A[i][j][k];
		int n1 = 0, n2 = 0;
		if (a[i] == 'C') n1 = 1;
		if (a[i] == 'T') n1 = 2;
		if (b[i] == 'C') n2 = 1;
		if (b[i] == 'T') n2 = 2;
		A[i+1][n1][n2]++;
	}
}

int get_distance(int x, int y) {
	int a = A[y+1][0][1] - A[x][0][1], b = A[y+1][0][2] - A[x][0][2], c = A[y+1][1][0] - A[x][1][0];
	int d = A[y+1][1][2] - A[x][1][2], e = A[y+1][2][0] - A[x][2][0], f = A[y+1][2][1] - A[x][2][1];
	int ans = 0;
	int n = min(a,c);
	ans += n, a -= n, c -= n;
	n = min(b,e), ans += n, b -= n, e -= n;
	n = min(d,f), ans += n, d -= n, f -= n;
	if (a == 0 && d == 0 && e == 0 && b == c && c == f) return ans + b * 2;
	if (b == 0 && c == 0 && f == 0 && a == d && d == e) return ans + a * 2;
	return -1;
}

Compilation message (stderr)

dna.cpp: In function 'void init(std::string, std::string)':
dna.cpp:9:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    9 |  for (int i = 0; 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...