제출 #779301

#제출 시각아이디문제언어결과실행 시간메모리
779301math_rabbit_1028로봇 (IOI13_robots)C++14
컴파일 에러
0 ms0 KiB
#include "robots.h"
using namespace std;
int a, b, t;

struct toy {
    int w, s;
    bool operator< (const toy &other) const {
        if (w == other.w) return s < other.s;
        return w < other.w;
    }
} toys[1010101];

bool compare(toy t1, toy t2) {
    if (t1.s == t2.s) return t1.w > t2.w;
    return t1.s > t2.s;
}

int wrbt[50505], srbt[50505];

priority_queue<toy> pq, pq2;

bool solve(int d) {
    while (!pq.empty()) pq.pop();
    while (!pq2.empty()) pq2.pop();

    int p = 1;
    long long remain = 0;
    for (int i = b; i >= 0; i--) {
        while (p <= t) {
            if (toys[p].s >= srbt[i]) {
                pq2.push(toys[p]);
                p++;
            }
            else break;
        }
        while (!pq2.empty()) {
            if (remain > 0) {
                pq2.pop();
                remain--;
            }
            else break;
        }
        while (!pq2.empty()) {
            pq.push(pq2.top());
            pq2.pop();
        }
        remain += d;
    }

    long long cnt = 0;
    for (int i = a; i >= 0; i--) {
        while (!pq.empty()) {
            if (pq.top().w >= wrbt[i]) {
                cnt++;
                pq.pop();
            }
            else break;
        }
        if (cnt > (long long)d * (a - i)) return false;
    }
    return true;
}

int putaway(int A, int B, int T, int X[], int Y[], int W[], int S[]) {
 
    a = A; b = B; t = T;
    for (int i = 1; i <= a; i++) wrbt[i] = X[i];
    for (int i = 1; i <= b; i++) srbt[i] = Y[i];
    for (int i = 1; i <= t; i++) {
        toys[i].w = W[i];
        toys[i].s = S[i];
    }

    sort(wrbt + 1, wrbt + a + 1);
    sort(srbt + 1, srbt + b + 1);
    sort(toys + 1, toys + t + 1, compare);

    for (int i = 1; i <= t; i++) {
        if (toys[i].w >= wrbt[a] && toys[i].s >= srbt[b]) {
            cout << "-1\n";
            return 0;
        }
    }

    int st = 1, ed = t;
    //assert(solve(t));
    while (st < ed) {
        int mid = (st + ed) / 2;
        if (solve(mid)) {
            ed = mid;
        }
        else {
            st = mid + 1;
        }
    }

    cout << st << "\n";

    return 0;
}

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

robots.cpp:20:1: error: 'priority_queue' does not name a type
   20 | priority_queue<toy> pq, pq2;
      | ^~~~~~~~~~~~~~
robots.cpp: In function 'bool solve(int)':
robots.cpp:23:13: error: 'pq' was not declared in this scope
   23 |     while (!pq.empty()) pq.pop();
      |             ^~
robots.cpp:24:13: error: 'pq2' was not declared in this scope
   24 |     while (!pq2.empty()) pq2.pop();
      |             ^~~
robots.cpp:31:17: error: 'pq2' was not declared in this scope
   31 |                 pq2.push(toys[p]);
      |                 ^~~
robots.cpp:36:17: error: 'pq2' was not declared in this scope
   36 |         while (!pq2.empty()) {
      |                 ^~~
robots.cpp:43:17: error: 'pq2' was not declared in this scope
   43 |         while (!pq2.empty()) {
      |                 ^~~
robots.cpp:44:13: error: 'pq' was not declared in this scope; did you mean 'p'?
   44 |             pq.push(pq2.top());
      |             ^~
      |             p
robots.cpp:52:17: error: 'pq' was not declared in this scope; did you mean 'p'?
   52 |         while (!pq.empty()) {
      |                 ^~
      |                 p
robots.cpp: In function 'int putaway(int, int, int, int*, int*, int*, int*)':
robots.cpp:74:5: error: 'sort' was not declared in this scope; did you mean 'short'?
   74 |     sort(wrbt + 1, wrbt + a + 1);
      |     ^~~~
      |     short
robots.cpp:80:13: error: 'cout' was not declared in this scope
   80 |             cout << "-1\n";
      |             ^~~~
robots.cpp:2:1: note: 'std::cout' is defined in header '<iostream>'; did you forget to '#include <iostream>'?
    1 | #include "robots.h"
  +++ |+#include <iostream>
    2 | using namespace std;
robots.cpp:97:5: error: 'cout' was not declared in this scope
   97 |     cout << st << "\n";
      |     ^~~~
robots.cpp:97:5: note: 'std::cout' is defined in header '<iostream>'; did you forget to '#include <iostream>'?