Submission #1011042

# Submission time Handle Problem Language Result Execution time Memory
1011042 2024-06-29T17:32:30 Z feukic Garage (IOI09_garage) C++14
100 / 100
1 ms 484 KB
#include <iostream>
#include <vector>
#include <string>
#include <utility>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>
#include <cmath>

using namespace std;

int findFree(vector<int> arr) {
    for (int i = 0; i < (int)arr.size(); i++) {
        if (arr[i] == 0) {
            return i;
        }
    }

    return arr.size();
}

int main() {
    ios_base::sync_with_stdio(0); cin.tie(NULL);

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

    vector<int> rate(n);
    for (int i = 0; i < n; i++) {
        cin >> rate[i];
    }

    vector<int> cars(m);
    for (int i = 0; i < m; i++) {
        cin >> cars[i];
    }

    queue<int> q;
    for (int i = 0; i < 2 * m; i++) {
        int c;
        cin >> c;

        q.push(c);
    }

    int sum = 0;
    int free = 0;
    vector<int> parking(n);
    queue<int> waiting;
    while (q.size()) {
        free = findFree(parking);
        if (q.front() > 0) {
            if (free == n) {
                waiting.push(q.front());
            } else {
                sum += rate[free] * cars[q.front() - 1];
                parking[free] = q.front();
            } q.pop(); 
        } else {
            for (int i = 0; i < n; i++) {
                if (-q.front() == parking[i]) {
                    parking[i] = 0;
                }
            } 
            
            if (waiting.size()) {
                q.front() = waiting.front();
                waiting.pop();
            } else {
                q.pop();
            }
        } 
    }

    cout << sum << endl;

    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 412 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 1 ms 344 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 1 ms 484 KB Output is correct
20 Correct 1 ms 348 KB Output is correct