제출 #1103115

#제출 시각아이디문제언어결과실행 시간메모리
1103115agrim_09DNA 돌연변이 (IOI21_dna)C++17
컴파일 에러
0 ms0 KiB
#include "dna.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:34:8: error: 'vector' does not name a type
   34 | int n; vector<vector<int>>cnt; string s1, s2;
      |        ^~~~~~
dna.cpp: In function 'void init(std::string, std::string)':
dna.cpp:38:20: error: 'vector' was not declared in this scope
   38 |     n = s1.size(); vector<int>temp(6,0);
      |                    ^~~~~~
dna.cpp:2:1: note: 'std::vector' is defined in header '<vector>'; did you forget to '#include <vector>'?
    1 | #include "dna.h"
  +++ |+#include <vector>
    2 | using namespace std;
dna.cpp:38:27: error: expected primary-expression before 'int'
   38 |     n = s1.size(); vector<int>temp(6,0);
      |                           ^~~
dna.cpp:40:9: error: 'cnt' was not declared in this scope; did you mean 'int'?
   40 |         cnt.pb(temp);
      |         ^~~
      |         int
dna.cpp:40:16: error: 'temp' was not declared in this scope; did you mean 'mktemp'?
   40 |         cnt.pb(temp);
      |                ^~~~
      |                mktemp
dna.cpp:45:9: error: 'cnt' was not declared in this scope; did you mean 'int'?
   45 |         cnt[0][val(s1[0],s2[0])] = 1;
      |         ^~~
      |         int
dna.cpp:50:13: error: 'cnt' was not declared in this scope; did you mean 'int'?
   50 |             cnt[i][j] = cnt[i-1][j];
      |             ^~~
      |             int
dna.cpp:54:13: error: 'cnt' was not declared in this scope; did you mean 'int'?
   54 |             cnt[i][val(s1[i],s2[i])]++;
      |             ^~~
      |             int
dna.cpp: In function 'int get_distance(int, int)':
dna.cpp:60:14: error: 'cnt' was not declared in this scope; did you mean 'int'?
   60 |     int x1 = cnt[r][0], x2 = cnt[r][1], y1 = cnt[r][2], y2 = cnt[r][3];
      |              ^~~
      |              int
dna.cpp:64:28: error: 'x2' was not declared in this scope; did you mean 'x1'?
   64 |         x1 -= cnt[l-1][0], x2 -= cnt[l-1][1], y1 -= cnt[l-1][2], y2 -= cnt[l-1][3];
      |                            ^~
      |                            x1
dna.cpp:64:47: error: 'y1' was not declared in this scope; did you mean 'z1'?
   64 |         x1 -= cnt[l-1][0], x2 -= cnt[l-1][1], y1 -= cnt[l-1][2], y2 -= cnt[l-1][3];
      |                                               ^~
      |                                               z1
dna.cpp:64:66: error: 'y2' was not declared in this scope; did you mean 's2'?
   64 |         x1 -= cnt[l-1][0], x2 -= cnt[l-1][1], y1 -= cnt[l-1][2], y2 -= cnt[l-1][3];
      |                                                                  ^~
      |                                                                  s2
dna.cpp:65:28: error: 'z2' was not declared in this scope; did you mean 'z1'?
   65 |         z1 -= cnt[l-1][4], z2 -= cnt[l-1][5];
      |                            ^~
      |                            z1
dna.cpp:68:22: error: 'y1' was not declared in this scope; did you mean 'z1'?
   68 |     int ans = min(x1,y1) + min(x2,z1) + min(y2,z2);
      |                      ^~
      |                      z1
dna.cpp:68:32: error: 'x2' was not declared in this scope; did you mean 'x1'?
   68 |     int ans = min(x1,y1) + min(x2,z1) + min(y2,z2);
      |                                ^~
      |                                x1
dna.cpp:68:45: error: 'y2' was not declared in this scope; did you mean 's2'?
   68 |     int ans = min(x1,y1) + min(x2,z1) + min(y2,z2);
      |                                             ^~
      |                                             s2
dna.cpp:68:48: error: 'z2' was not declared in this scope; did you mean 'z1'?
   68 |     int ans = min(x1,y1) + min(x2,z1) + min(y2,z2);
      |                                                ^~
      |                                                z1
dna.cpp:69:5: error: 'set' was not declared in this scope
   69 |     set<int>front; set<int>end;
      |     ^~~
dna.cpp:2:1: note: 'std::set' is defined in header '<set>'; did you forget to '#include <set>'?
    1 | #include "dna.h"
  +++ |+#include <set>
    2 | using namespace std;
dna.cpp:69:9: error: expected primary-expression before 'int'
   69 |     set<int>front; set<int>end;
      |         ^~~
dna.cpp:69:24: error: expected primary-expression before 'int'
   69 |     set<int>front; set<int>end;
      |                        ^~~
dna.cpp:74:9: error: 'front' was not declared in this scope
   74 |         front.insert(1); end.insert(2);
      |         ^~~~~
dna.cpp:74:30: error: overloaded function with no contextual type information
   74 |         front.insert(1); end.insert(2);
      |                              ^~~~~~
dna.cpp:77:9: error: 'front' was not declared in this scope
   77 |         front.insert(2); end.insert(1);
      |         ^~~~~
dna.cpp:77:30: error: overloaded function with no contextual type information
   77 |         front.insert(2); end.insert(1);
      |                              ^~~~~~
dna.cpp:80:9: error: 'front' was not declared in this scope
   80 |         front.insert(1); end.insert(3);
      |         ^~~~~
dna.cpp:80:30: error: overloaded function with no contextual type information
   80 |         front.insert(1); end.insert(3);
      |                              ^~~~~~
dna.cpp:83:9: error: 'front' was not declared in this scope
   83 |         front.insert(3); end.insert(1);
      |         ^~~~~
dna.cpp:83:30: error: overloaded function with no contextual type information
   83 |         front.insert(3); end.insert(1);
      |                              ^~~~~~
dna.cpp:86:9: error: 'front' was not declared in this scope
   86 |         front.insert(2); end.insert(3);
      |         ^~~~~
dna.cpp:86:30: error: overloaded function with no contextual type information
   86 |         front.insert(2); end.insert(3);
      |                              ^~~~~~
dna.cpp:89:9: error: 'front' was not declared in this scope
   89 |         front.insert(3); end.insert(2);
      |         ^~~~~
dna.cpp:89:30: error: overloaded function with no contextual type information
   89 |         front.insert(3); end.insert(2);
      |                              ^~~~~~
dna.cpp:92:17: error: 'front' was not declared in this scope
   92 |     bool yes = (front==end and r1==r2 and r2==r3);
      |                 ^~~~~
dna.cpp:92:36: error: 'r2' was not declared in this scope; did you mean 'r1'?
   92 |     bool yes = (front==end and r1==r2 and r2==r3);
      |                                    ^~
      |                                    r1
dna.cpp:92:47: error: 'r3' was not declared in this scope; did you mean 'r1'?
   92 |     bool yes = (front==end and r1==r2 and r2==r3);
      |                                               ^~
      |                                               r1