답안 #727963

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
727963 2023-04-21T17:09:18 Z Vlatko09 Garage (IOI09_garage) C++14
컴파일 오류
0 ms 0 KB
include <bits/stdc++.h>
using namespace std;
int main() {
    int n, m;
    cin >> n >> m;
    vector<int> rates(n);
    for (int i = 0; i < n; i++) {
        cin >> rates[i];
    }
    priority_queue<pair<int, int>, vector<pair<int, int>>, greater<pair<int, int>>> arrivals;
    vector<int> weights(m);
    for (int i = 0; i < 2 * m; i++) {
        int car;
        cin >> car;
        if (car > 0) {
            int weight;
            cin >> weight;
            weights[car - 1] = weight;
            arrivals.emplace(i, car - 1);
        } else {
            car = -car;
            int space = -1;
            int cost = 0;
            for (int j = 0; j < n; j++) {
                if (space < 0 || rates[j] < rates[space]) {
                    space = j;
                }
            }
            if (space >= 0) {
                cost = rates[space] * weights[car - 1];
            }
            cout << cost << endl;
        }
    }
    priority_queue<pair<int, int>, vector<pair<int, int>>, greater<pair<int, int>>> releases;
    vector<bool> occupied(n);
    int revenue = 0;
    while (!arrivals.empty()) {
        auto [time, car] = arrivals.top();
        arrivals.pop();
        int space = -1;
        for (int i = 0; i < n; i++) {
            if (!occupied[i] && (space < 0 || rates[i] < rates[space])) {
                space = i;
            }
        }
        if (space >= 0) {
            occupied[space] = true;
            revenue += rates[space] * weights[car];
            releases.emplace(time + n, space);
        } else {
            arrivals.emplace(time + 1, car);
        }
    }
    while (!releases.empty()) {
        auto [time, space] = releases.top();
        releases.pop();
        occupied[space] = false;
    }
    cout << revenue << endl;
    return 0;
}

Compilation message

garage.cpp:1:1: error: 'include' does not name a type
    1 | include <bits/stdc++.h>
      | ^~~~~~~
garage.cpp: In function 'int main()':
garage.cpp:5:5: error: 'cin' was not declared in this scope
    5 |     cin >> n >> m;
      |     ^~~
garage.cpp:6:5: error: 'vector' was not declared in this scope
    6 |     vector<int> rates(n);
      |     ^~~~~~
garage.cpp:6:12: error: expected primary-expression before 'int'
    6 |     vector<int> rates(n);
      |            ^~~
garage.cpp:8:16: error: 'rates' was not declared in this scope
    8 |         cin >> rates[i];
      |                ^~~~~
garage.cpp:10:5: error: 'priority_queue' was not declared in this scope
   10 |     priority_queue<pair<int, int>, vector<pair<int, int>>, greater<pair<int, int>>> arrivals;
      |     ^~~~~~~~~~~~~~
garage.cpp:10:20: error: 'pair' was not declared in this scope
   10 |     priority_queue<pair<int, int>, vector<pair<int, int>>, greater<pair<int, int>>> arrivals;
      |                    ^~~~
garage.cpp:10:25: error: expected primary-expression before 'int'
   10 |     priority_queue<pair<int, int>, vector<pair<int, int>>, greater<pair<int, int>>> arrivals;
      |                         ^~~
garage.cpp:11:12: error: expected primary-expression before 'int'
   11 |     vector<int> weights(m);
      |            ^~~
garage.cpp:18:13: error: 'weights' was not declared in this scope; did you mean 'weight'?
   18 |             weights[car - 1] = weight;
      |             ^~~~~~~
      |             weight
garage.cpp:19:13: error: 'arrivals' was not declared in this scope
   19 |             arrivals.emplace(i, car - 1);
      |             ^~~~~~~~
garage.cpp:25:34: error: 'rates' was not declared in this scope
   25 |                 if (space < 0 || rates[j] < rates[space]) {
      |                                  ^~~~~
garage.cpp:30:24: error: 'rates' was not declared in this scope
   30 |                 cost = rates[space] * weights[car - 1];
      |                        ^~~~~
garage.cpp:30:39: error: 'weights' was not declared in this scope
   30 |                 cost = rates[space] * weights[car - 1];
      |                                       ^~~~~~~
garage.cpp:32:13: error: 'cout' was not declared in this scope; did you mean 'cost'?
   32 |             cout << cost << endl;
      |             ^~~~
      |             cost
garage.cpp:32:29: error: 'endl' was not declared in this scope
   32 |             cout << cost << endl;
      |                             ^~~~
garage.cpp:35:25: error: expected primary-expression before 'int'
   35 |     priority_queue<pair<int, int>, vector<pair<int, int>>, greater<pair<int, int>>> releases;
      |                         ^~~
garage.cpp:36:12: error: expected primary-expression before 'bool'
   36 |     vector<bool> occupied(n);
      |            ^~~~
garage.cpp:38:13: error: 'arrivals' was not declared in this scope
   38 |     while (!arrivals.empty()) {
      |             ^~~~~~~~
garage.cpp:39:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   39 |         auto [time, car] = arrivals.top();
      |              ^
garage.cpp:43:18: error: 'occupied' was not declared in this scope
   43 |             if (!occupied[i] && (space < 0 || rates[i] < rates[space])) {
      |                  ^~~~~~~~
garage.cpp:43:47: error: 'rates' was not declared in this scope
   43 |             if (!occupied[i] && (space < 0 || rates[i] < rates[space])) {
      |                                               ^~~~~
garage.cpp:48:13: error: 'occupied' was not declared in this scope
   48 |             occupied[space] = true;
      |             ^~~~~~~~
garage.cpp:49:24: error: 'rates' was not declared in this scope
   49 |             revenue += rates[space] * weights[car];
      |                        ^~~~~
garage.cpp:49:39: error: 'weights' was not declared in this scope
   49 |             revenue += rates[space] * weights[car];
      |                                       ^~~~~~~
garage.cpp:50:13: error: 'releases' was not declared in this scope
   50 |             releases.emplace(time + n, space);
      |             ^~~~~~~~
garage.cpp:55:13: error: 'releases' was not declared in this scope
   55 |     while (!releases.empty()) {
      |             ^~~~~~~~
garage.cpp:56:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   56 |         auto [time, space] = releases.top();
      |              ^
garage.cpp:58:9: error: 'occupied' was not declared in this scope
   58 |         occupied[space] = false;
      |         ^~~~~~~~
garage.cpp:60:5: error: 'cout' was not declared in this scope
   60 |     cout << revenue << endl;
      |     ^~~~
garage.cpp:60:24: error: 'endl' was not declared in this scope
   60 |     cout << revenue << endl;
      |                        ^~~~