Submission #872607

#TimeUsernameProblemLanguageResultExecution timeMemory
872607LucaLucaMDNA 돌연변이 (IOI21_dna)C++17
100 / 100
32 ms7776 KiB
#include "dna.h"
#include <iostream>
#include <algorithm>

std::string s, q;
int n;

const int NMAX = 1e5;

int sum[NMAX + 1][3][3];

void init(std::string a, std::string b) {
  n = (int) a.size();
  for (auto &ch : a) {
    if (ch == 'A') {
      ch = 0;
    } else if (ch == 'C') {
      ch = 1;
    } else {
      ch = 2;
    }
  }
  for (auto &ch : b) {
    if (ch == 'A') {
      ch = 0;
    } else if (ch == 'C') {
      ch = 1;
    } else {
      ch = 2;
    }
  }
  s = '$' + a, q = '$' + b;
  for (int i = 1; i <= n; i++) {
    for (int j = 0; j < 3; j++) {
      for (int k = 0; k < 3; k++) {
        sum[i][j][k] = sum[i - 1][j][k];
      }
    }
    sum[i][s[i]][q[i]]++;
  }
}

int get_distance(int x, int y) {
  ++x, ++y;
  int cnt[3][3] = {};
  int delta[3] = {};
  for (int i = 0; i < 3; i++) {
    for (int j = 0; j < 3; j++) {
      cnt[i][j] = sum[y][i][j] - sum[x - 1][i][j];
      delta[i] += cnt[i][j];
      delta[j] -= cnt[i][j];
    }
  }
  if (delta[0] != 0 || delta[1] != 0 || delta[2] != 0) {
    return -1;
  }
  std::vector<int> p = {0, 1, 2};
  int answer = 0;
  do {
    int cur = 0;
    for (int i = 0; i < 3; i++) {
      for (int j = i + 1; j < 3; j++) {
        cur += cnt[p[i]][p[j]];
      }
    }
    answer = std::max(answer, cur);
  } while (std::next_permutation(p.begin(), p.end()));
  return answer;
}

/**
6 3
ATACAT
ACTATA
1 3
4 5
3 5

123
231

**/

Compilation message (stderr)

dna.cpp: In function 'void init(std::string, std::string)':
dna.cpp:39:16: warning: array subscript has type 'char' [-Wchar-subscripts]
   39 |     sum[i][s[i]][q[i]]++;
      |                ^
dna.cpp:39:22: warning: array subscript has type 'char' [-Wchar-subscripts]
   39 |     sum[i][s[i]][q[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...