Submission #423285

# Submission time Handle Problem Language Result Execution time Memory
423285 2021-06-10T22:04:28 Z haxorman Garage (IOI09_garage) C++14
100 / 100
3 ms 332 KB
#include <bits/stdc++.h>
using namespace std;

const int mxN = 107;
const int mxM = 2007;

bool arr[mxN];
int r[mxN], w[mxM], pos[mxM];

int32_t main() {
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

    int n, m;
    cin >> n >> m;

    for (int i = 1; i <= n; ++i) {
        cin >> r[i];
    }

    for (int i = 1; i <= m; ++i) {
        cin >> w[i];
    }

    long long ans = 0;
    queue<int> q;
    for (int iter = 1; iter <= 2 * m; ++iter) {
        int car;
        cin >> car;

        if (car < 0) {
            car = -car;

            arr[pos[car]] = false;
            for (int i = 1; i <= n && q.size(); ++i) {
                if (!arr[i]) {
                    //cout << q.front() << ' ' << i << "\n";
                    arr[i] = true;

                    ans += r[i] * w[q.front()];
                    pos[q.front()] = i;
                    q.pop();
                }
            }
        }
        else {
            q.push(car);
            for (int i = 1; i <= n && q.size(); ++i) {
                if (!arr[i]) {
                    //cout << q.front() << ' ' << i << "\n";
                    arr[i] = true;

                    ans += r[i] * w[q.front()];
                    pos[q.front()] = i;
                    q.pop();
                }
            }
        }
    }
    cout << ans << "\n";
}
# Verdict Execution time Memory Grader output
1 Correct 0 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 0 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 0 ms 204 KB Output is correct
8 Correct 0 ms 204 KB Output is correct
9 Correct 0 ms 204 KB Output is correct
10 Correct 0 ms 204 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
16 Correct 1 ms 204 KB Output is correct
17 Correct 1 ms 204 KB Output is correct
18 Correct 2 ms 204 KB Output is correct
19 Correct 3 ms 332 KB Output is correct
20 Correct 1 ms 332 KB Output is correct