답안 #1081089

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1081089 2024-08-29T18:15:17 Z codexistent 열대 식물원 (Tropical Garden) (IOI11_garden) C++14
컴파일 오류
0 ms 0 KB
#include "garden.h"
#include "gardenlib.h"
#include <bits/stdc++.h>
#define MAXN 150005
#define LOGN 31
#define FOR(i, a, b) for(int i = a; i <= b; i++)

pair<int, int> jmp[MAXN][LOGN][2];
int ch[MAXN][2];

void count_routes(int N, int M, int P, int R[][2], int Q, int G[])
{
    FOR(i, 1, N) ch[i][0] = ch[i][1] = N + 1;
    FOR(i, 1, M){
        int x = R[i][0], y = R[i][1];
        if(x < ch[y][0]){
            ch[y][1] = ch[y][0];
            ch[y][0] = x;
        }else if(x < ch[y][1]){
            ch[y][1] = x;
        }

        if(y < ch[x][0]){
            ch[x][1] = ch[x][0];
            ch[x][0] = y;
        }else if(y < ch[x][1]){
            ch[x][1] = y;
        }
    }
    FOR(i, 1, N){
        jmp[i][0][0] = {ch[i][0], i};
        if(ch[i][1] == N + 1){
            jmp[i][0][0].first = -1;            
        }else{
            jmp[i][0][1] = {ch[i][1], i};
        }
    }

    // jmp[node][jump size][next node] = 
    FOR(i, 1, N){
        for(int j = 1, j <= LOGN - 1; j++){
            // jmp[i][j][0]
            int hi = jmp[i][j - 1][0].first, h2i = jmp[i][j - 1][0].second;
            if(ch[hi][0] != h2i || jmp[hi][j - 1][1].first == -1){
                jmp[i][j][0] = jmp[hi][j - 1][0];
            }else{
                jmp[i][j][0] = jmp[hi][j - 1][1];
            }

            // jmp[i][j][1]
            if(jmp[i][j - 1][1].first == -1){
                jmp[i][j][1].first = -1;
                continue;
            }
            hi = jmp[i][j - 1][1].first, h2i = jmp[i][j - 1][0].second;
            if(ch[hi][0] != h2i || jmp[hi][j - 1][1].first == -1){
                jmp[i][j][1] = jmp[hi][j - 1][0];
            }else{
                jmp[i][j][1] = jmp[hi][j - 1][1];
            }
        }
    }

    FOR(q, 1, Q){
        int r = 0, jd = G[q - 1];
        FOR(s, 1, N){
            int i = s, i2 = 0;
            FOR(j, 0, LOGN - 1){
                if((1 << j) & jd){
                    if(ch[i][0] != i2 || jmp[i][j][1].first == -1){
                        i2 = jmp[i][j][0].second, i = jmp[i][j][0].first;
                    }else{
                        i2 = jmp[i][j][1].second, i = jmp[i][j][1].first;
                    }
                }
            }
            if(i == P) r++;
        }

        answer(r);
    }
}

Compilation message

garden.cpp:8:1: error: 'pair' does not name a type
    8 | pair<int, int> jmp[MAXN][LOGN][2];
      | ^~~~
garden.cpp: In function 'void count_routes(int, int, int, int (*)[2], int, int*)':
garden.cpp:31:9: error: 'jmp' was not declared in this scope
   31 |         jmp[i][0][0] = {ch[i][0], i};
      |         ^~~
garden.cpp:41:25: error: expected ';' before '<=' token
   41 |         for(int j = 1, j <= LOGN - 1; j++){
      |                         ^~~
      |                         ;
garden.cpp:41:26: error: expected primary-expression before '<=' token
   41 |         for(int j = 1, j <= LOGN - 1; j++){
      |                          ^~
garden.cpp:43:22: error: 'jmp' was not declared in this scope
   43 |             int hi = jmp[i][j - 1][0].first, h2i = jmp[i][j - 1][0].second;
      |                      ^~~
garden.cpp:44:29: error: 'h2i' was not declared in this scope; did you mean 'hi'?
   44 |             if(ch[hi][0] != h2i || jmp[hi][j - 1][1].first == -1){
      |                             ^~~
      |                             hi
garden.cpp:55:42: error: 'h2i' was not declared in this scope; did you mean 'hi'?
   55 |             hi = jmp[i][j - 1][1].first, h2i = jmp[i][j - 1][0].second;
      |                                          ^~~
      |                                          hi
garden.cpp:70:42: error: 'jmp' was not declared in this scope
   70 |                     if(ch[i][0] != i2 || jmp[i][j][1].first == -1){
      |                                          ^~~