Submission #462961

# Submission time Handle Problem Language Result Execution time Memory
462961 2021-08-11T02:12:33 Z danielsuh Garage (IOI09_garage) C++17
50 / 100
2 ms 588 KB
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
#define int ll

const int mxN = 2005;
int carSpot[mxN];

int32_t main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
    int N, M; cin >> N >> M;
    vector<int> prices(N + 1), cars(M + 1);
    for(int i = 1; i <= N; i++) cin >> prices[i];
    for(int i = 1; i <= M; i++) cin >> cars[i];
    set<int> free;
    for(int i = 1; i <= N; i++) {
        free.insert(i);
    }
    deque<int> line;
    int ans = 0;
    for(int i = 0; i < 2 * M; i++) {
        int step; cin >> step;
        //for(auto &x : free) cout << x << " ";
        //cout << "\n";
        if(step > 0) {
            if(free.empty()) {
                line.push_back(step);
                continue;
            }
            int space = *free.begin();
            free.erase(*free.begin());
            ans += cars[step] * prices[space];
            carSpot[step] = space;
        }else {
            free.insert(carSpot[-step]);
            assert(carSpot[-step] != 0);
            if(line.size() > 1) {
                assert(free.size() == 1);
            }
            if(!free.empty() && !line.empty()) {
                int car = *line.begin();
                ans += cars[car] * prices[carSpot[-step]];
                carSpot[car] = carSpot[-step];
                line.pop_front();
            }
        }
    }
    cout << ans << "\n";
}

# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Runtime error 1 ms 476 KB Execution killed with signal 6
7 Correct 1 ms 204 KB Output is correct
8 Incorrect 1 ms 204 KB Output isn't correct
9 Correct 1 ms 204 KB Output is correct
10 Runtime error 2 ms 460 KB Execution killed with signal 6
11 Correct 1 ms 204 KB Output is correct
12 Runtime error 1 ms 460 KB Execution killed with signal 6
13 Correct 1 ms 204 KB Output is correct
14 Incorrect 1 ms 204 KB Output isn't correct
15 Correct 1 ms 204 KB Output is correct
16 Runtime error 2 ms 460 KB Execution killed with signal 6
17 Runtime error 2 ms 460 KB Execution killed with signal 6
18 Runtime error 2 ms 472 KB Execution killed with signal 6
19 Runtime error 2 ms 588 KB Execution killed with signal 6
20 Runtime error 2 ms 460 KB Execution killed with signal 6