제출 #1363608

#제출 시각아이디문제언어결과실행 시간메모리
1363608yavor_ptvDNA 돌연변이 (IOI21_dna)C++20
컴파일 에러
0 ms0 KiB
// SUBTASK 1 + 2 + 4
#include <bits/stdc++.h>
#include "dna.h"
//#include "grader.cpp"

using namespace std;

string a, b;
vector <int> pref;
vector <vector<int>> pref_a;
vector <vector<int>> pref_b;
vector <vector<int>> cnt(3, vector<int>(3));

int id(char ch)
{
    if (ch == 'A') return 0;
    if (ch == 'T') return 1;
    return 2;
}

void init(string A, string B)
{
    a = A;
    b = B;
    int n = a.size();
    pref.resize(n);
    pref_a.resize(3, vector<int>(n));
    pref_b.resize(3, vector<int>(n));

    int id;
    for (int i = 0; i < n; i++)
    {
        id = id(a[i]);
        pref_a[id][i] = i > 0 ? pref_a[id][i - 1] + 1 : 1;
        pref_a[id][i] = i > 0 ? pref_a[id][i - 1] : 0;

        id = id(b[i]);
        pref_b[id][i] = i > 0 ? pref_b[id][i - 1] + 1 : 1;
        pref_b[id][i] = i > 0 ? pref_b[id][i - 1] : 0;

        if (a[i] != b[i])
        {
            pref[i] = i > 0 ? pref[i - 1] + 1 : 1;
        }
        else pref[i] = i > 0 ? pref[i - 1] : 0;
    }


}

bool validate(int x, int y)
{
    int br_aA = x > 0 ? pref_a[0][y] - pref_a[0][x - 1] : pref_a[0][y];
    int br_aT = x > 0 ? pref_a[1][y] - pref_a[1][x - 1] : pref_a[1][y];
    int br_aC = x > 0 ? pref_a[2][y] - pref_a[2][x - 1] : pref_a[2][y];

    int br_bA = x > 0 ? pref_b[0][y] - pref_b[0][x - 1] : pref_b[0][y];
    int br_bT = x > 0 ? pref_b[1][y] - pref_b[1][x - 1] : pref_b[1][y];
    int br_bC = x > 0 ? pref_b[2][y] - pref_b[2][x - 1] : pref_b[2][y];

    return (br_aA == br_bA && br_aT == br_bT && br_aC == br_bC);
}

int get_distance(int x, int y)
{
    if (!validate(x, y)) return -1;
    cnt.assign(3, vector<int>(3));

    for (int i = x; i <= y; i++)
    {
        if (a[i] == b[i]) continue;
        int id1 = id(a[i]), id2 = id(b[i]);
        cnt[id1][id2]++;
    }

    int ans = 0, remain = 0, id1, id2;
    id1 = id('A'); id2 = id('T');
    int swaps1 = min(cnt[id1][id2], cnt[id1][id2]);
    remain += max(cnt[id1][id2], cnt[id1][id2]) - swaps1;
    ans += swaps1;

    id1 = id('A'); id2 = id('C');
    int swaps2 = min(cnt[id1][id2], cnt[id1][id2]);
    remain += max(cnt[id1][id2], cnt[id1][id2]) - swaps2;
    ans += swaps2;

    id1 = id('T'); id2 = id('C');
    int swaps3 = min(cnt[id1][id2], cnt[id1][id2]);
    remain += max(cnt[id1][id2], cnt[id1][id2]) - swaps3;
    ans += swaps3;

    ans += (remain / 3) * 2;

    return ans;
}



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


2
1
-1

2 1
AA
TT
0 1
*/

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

dna.cpp: In function 'void init(std::string, std::string)':
dna.cpp:33:16: error: 'id' cannot be used as a function
   33 |         id = id(a[i]);
      |              ~~^~~~~~
dna.cpp:37:16: error: 'id' cannot be used as a function
   37 |         id = id(b[i]);
      |              ~~^~~~~~