제출 #607607

#제출 시각아이디문제언어결과실행 시간메모리
607607jairRSDNA 돌연변이 (IOI21_dna)C++17
0 / 100
194 ms65184 KiB
#include "dna.h"
#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;

string ga, gb;
map<char, vi> prefixCharA, prefixCharB;
// prefix array of the positions where [c1][c2] c2 is in b instead of c1
map<char, map<char, int>> inPlaceOf[(int)1e5 + 1];
char characters[3] = {'A', 'T', 'C'};

void init(string a, string b)
{
    int n = a.size();
    ga = ' ' + a;
    gb = ' ' + b;
    for (char c : characters)
    {
        prefixCharA[c] = prefixCharB[c] = vi(n + 1, 0);
        for (int i = 1; i <= n; i++)
        {
            prefixCharA[c][i] = (ga[i] == c) + prefixCharA[c][i - 1];
            prefixCharB[c][i] = (gb[i] == c) + prefixCharB[c][i - 1];

            for (int j = 0; j < 3; j++)
                for (int k = 0; k < 3; k++)
                {
                    if (k == j)
                        continue;
                    inPlaceOf[i][characters[j]][characters[k]] =
                        inPlaceOf[i - 1][characters[j]][characters[k]];
                }

            if (b[i] != a[i])
                inPlaceOf[i][a[i]][b[i]]++;
        }
    }
}

int get_distance(int x, int y)
{
    x++, y++;

    bool pos = true;
    for (char c : characters)
    {
        int countInA = prefixCharA[c][y] - prefixCharA[c][x - 1];
        int countInB = prefixCharB[c][y] - prefixCharB[c][x - 1];
        pos &= (countInA == countInB);
    }

    if (!pos)
        return -1;

    int moves = 0;
    return inPlaceOf[y]['A']['T'] - inPlaceOf[x - 1]['A']['T'];
}

컴파일 시 표준 에러 (stderr) 메시지

dna.cpp: In function 'int get_distance(int, int)':
dna.cpp:55:9: warning: unused variable 'moves' [-Wunused-variable]
   55 |     int moves = 0;
      |         ^~~~~
#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...