답안 #406529

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
406529 2021-05-17T17:25:06 Z snasibov05 식물 비교 (IOI20_plants) C++14
컴파일 오류
0 ms 0 KB
#include "plants.h"

#define pb push_back

using namespace std;

vector<int> h;

void init(int k, vector<int> r) {
    int n = r.size();
    int x = n;
    h.resize(n);

    for (int i = 0; i < n; ++i) {
        r.pb(r[i]);
    }

    for (int i = 0; i < n; ++i) {

        queue<int> q;

        for (int j = 0; j < n; ++j) {
            if (!q.empty() && j - q.front() > k - 1) q.pop();
            if (r[j] == 0) q.push(r[j]);
        }

        int cur = 0;

        for (int j = n; j < 2*n; ++j) {
            if (!q.empty() && j - q.front() > k - 1) q.pop();
            if (r[j] == 0 && q.empty()){
                cur = j;
                break;
            }
            if (r[j] == 0) q.push(r[j]);
        }

        h[cur%n] = x--;

        for (int j = cur; j > cur - k ; --j) {
            r[j]--;
            if (j >= n) r[j-n]--;
            else r[j+n]--;
        }
    }

}

int compare_plants(int x, int y) {
    if (h[x] > h[y]) return 1;
    else return -1;

}

Compilation message

plants.cpp: In function 'void init(int, std::vector<int>)':
plants.cpp:20:9: error: 'queue' was not declared in this scope
   20 |         queue<int> q;
      |         ^~~~~
plants.cpp:2:1: note: 'std::queue' is defined in header '<queue>'; did you forget to '#include <queue>'?
    1 | #include "plants.h"
  +++ |+#include <queue>
    2 | 
plants.cpp:20:15: error: expected primary-expression before 'int'
   20 |         queue<int> q;
      |               ^~~
plants.cpp:23:18: error: 'q' was not declared in this scope
   23 |             if (!q.empty() && j - q.front() > k - 1) q.pop();
      |                  ^
plants.cpp:24:28: error: 'q' was not declared in this scope
   24 |             if (r[j] == 0) q.push(r[j]);
      |                            ^
plants.cpp:30:18: error: 'q' was not declared in this scope
   30 |             if (!q.empty() && j - q.front() > k - 1) q.pop();
      |                  ^
plants.cpp:31:30: error: 'q' was not declared in this scope
   31 |             if (r[j] == 0 && q.empty()){
      |                              ^
plants.cpp:35:28: error: 'q' was not declared in this scope
   35 |             if (r[j] == 0) q.push(r[j]);
      |                            ^