제출 #1103116

#제출 시각아이디문제언어결과실행 시간메모리
1103116agrim_09DNA 돌연변이 (IOI21_dna)C++17
컴파일 에러
0 ms0 KiB
#include "dna.h"
#include <bits/stdc++.h>
using namespace std; 
// Check for queue, priorioty_queue, stack, ordered_set solutions
// stack => LIFO (whatever goes in last comes out last)
// queue => FIFO (whatever goes in first comes out first)
// priority_queue => Dynamic queries of minimum/maximum
// ordered_set => set in vector form
//[order_of_key(k) gives number of elements less than k, while find_by_order(i) gives i^th element]
 
// To comment multiple lines : ctrl + /
// To find and replace : ctrl+H
 
int val(char a, char b){
    if(a==b){
        return -1;
    }
    if(a=='1'){
       return (b-'2');
    }
    if(a=='2'){
        if(b=='1'){
            return 2;
        }
        return 3;
    }
    if(a=='3'){
        if(b=='1'){
            return 4;
        }
        return 5;
    }
    return -1;
}
int n; vector<vector<int>>cnt; string s1, s2;

void init(string p, string q){
    s1 = p, s2 = q;
    n = s1.size(); vector<int>temp(6,0);
    for(int i = 0;i<n;i++){
        cnt.pb(temp);
    }

    int tmp = val(s1[0],s2[0]);
    if(tmp!=-1){
        cnt[0][val(s1[0],s2[0])] = 1;
    }
 
    for(int i = 1;i<n;i++){
        for(int j = 0;j<6;j++){
            cnt[i][j] = cnt[i-1][j];
        }
        int tmp = val(s1[i],s2[i]);
        if(tmp!=-1){
            cnt[i][val(s1[i],s2[i])]++;
        }
    }
}

int get_distance(int l, int r){
    int x1 = cnt[r][0], x2 = cnt[r][1], y1 = cnt[r][2], y2 = cnt[r][3];
    int z1 = cnt[r][4], z2 = cnt[r][5];

    if(l>0){
        x1 -= cnt[l-1][0], x2 -= cnt[l-1][1], y1 -= cnt[l-1][2], y2 -= cnt[l-1][3];
        z1 -= cnt[l-1][4], z2 -= cnt[l-1][5]; 
    }

    int ans = min(x1,y1) + min(x2,z1) + min(y2,z2);
    set<int>front; set<int>end;

    int r1 = abs(x1-y1), r2 =abs(x2-z1), r3 = abs(y2-z2);

    if(x1>y1){
        front.insert(1); end.insert(2); 
    }
    if(y1>x1){
        front.insert(2); end.insert(1);
    }
    if(x2>z1){
        front.insert(1); end.insert(3);
    }
    if(z1>x2){
        front.insert(3); end.insert(1); 
    }
    if(y2>z2){
        front.insert(2); end.insert(3); 
    }
    if(z2>y2){
        front.insert(3); end.insert(2); 
    }

    bool yes = (front==end and r1==r2 and r2==r3);
    if(yes){
        return ans + 2*r1;
    }
    else{
        return -1;
    }
}

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

dna.cpp: In function 'void init(std::string, std::string)':
dna.cpp:41:13: error: 'class std::vector<std::vector<int> >' has no member named 'pb'
   41 |         cnt.pb(temp);
      |             ^~