Submission #727964

# Submission time Handle Problem Language Result Execution time Memory
727964 2023-04-21T17:10:26 Z Vlatko09 Garage (IOI09_garage) C++14
0 / 100
1000 ms 468 KB
#include <iostream>
#include <queue>
#include <tuple>
#include <vector>
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: In function 'int main()':
garage.cpp:42:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   42 |         auto [time, car] = arrivals.top();
      |              ^
garage.cpp:59:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   59 |         auto [time, space] = releases.top();
      |              ^
# Verdict Execution time Memory Grader output
1 Execution timed out 1073 ms 300 KB Time limit exceeded
2 Execution timed out 1085 ms 212 KB Time limit exceeded
3 Runtime error 1 ms 340 KB Execution killed with signal 6
4 Execution timed out 1076 ms 212 KB Time limit exceeded
5 Runtime error 1 ms 432 KB Execution killed with signal 6
6 Runtime error 1 ms 340 KB Execution killed with signal 6
7 Runtime error 1 ms 340 KB Execution killed with signal 6
8 Runtime error 1 ms 428 KB Execution killed with signal 11
9 Runtime error 1 ms 340 KB Execution killed with signal 6
10 Runtime error 1 ms 340 KB Execution killed with signal 6
11 Execution timed out 1081 ms 212 KB Time limit exceeded
12 Execution timed out 1079 ms 212 KB Time limit exceeded
13 Runtime error 2 ms 468 KB Execution killed with signal 11
14 Execution timed out 1079 ms 304 KB Time limit exceeded
15 Runtime error 1 ms 468 KB Execution killed with signal 6
16 Runtime error 1 ms 468 KB Execution killed with signal 6
17 Execution timed out 1084 ms 340 KB Time limit exceeded
18 Runtime error 1 ms 468 KB Execution killed with signal 6
19 Runtime error 5 ms 468 KB Execution killed with signal 6
20 Runtime error 1 ms 468 KB Execution killed with signal 6