Submission #522412

# Submission time Handle Problem Language Result Execution time Memory
522412 2022-02-04T22:56:21 Z nurlitadf Garage (IOI09_garage) C++17
10 / 100
2 ms 460 KB
#include <bits/stdc++.h>
#define ll long long
using namespace std;

ll modexp(ll b, ll e, ll m){
    ll r = 1;
    while(e > 0){
     if((e & 1) == 1){
         r = (r * b) % m;
     }
     e >>= 1;
     b = (b * b) % m;
    }
    return r;
}

bool isvowel(char ch) { 
    return (ch == 'a') || (ch == 'e') ||(ch == 'i') ||(ch == 'o') ||(ch == 'u') ||(ch == 'y'); 
}

int main() {
    int n, m;
    cin >> n >> m;

    vector<int> rates;
    for(int i = 0; i < n; i++) {
        int v;
        cin >> v;

        rates.push_back(v);
    }

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

        cars.push_back(v);
    }

    vector<int> space(n, -1);
    vector<int> car_to_space(n, -1);
    ll ans = 0;
    queue<int> q;

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

        if(v > 0) {
            v--;
            bool found = false;
            for(int j = 0; j < n; j++) {
                if(space[j] == -1) {
                    space[j] = v;
                    car_to_space[v] = j;

                    ans += rates[j] * cars[v];
                    found = true;
                    // cout << "~~~ " << v << " " << j << endl;
                    break;
                }
            }

            if(!found)
                q.push(v);
        } else {
            v = abs(v) - 1;
            int s = car_to_space[v];
            space[s] = -1;
            if(!q.empty()) {
                int c = q.front();
                q.pop();

                space[s] = c;
                car_to_space[c] = s;
                ans += rates[s] * cars[c];
            }

            car_to_space[v] = -1;
        }
    }

    cout << ans << endl;

    return 0;
}
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 332 KB Execution killed with signal 6
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Runtime error 1 ms 332 KB Execution killed with signal 6
5 Runtime error 1 ms 332 KB Execution killed with signal 6
6 Runtime error 1 ms 332 KB Execution killed with signal 11
7 Runtime error 1 ms 332 KB Execution killed with signal 6
8 Runtime error 1 ms 332 KB Execution killed with signal 6
9 Runtime error 1 ms 332 KB Execution killed with signal 6
10 Runtime error 1 ms 332 KB Execution killed with signal 11
11 Runtime error 1 ms 332 KB Execution killed with signal 6
12 Runtime error 1 ms 332 KB Execution killed with signal 6
13 Runtime error 1 ms 332 KB Execution killed with signal 6
14 Runtime error 1 ms 332 KB Execution killed with signal 6
15 Runtime error 1 ms 332 KB Execution killed with signal 6
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 460 KB Execution killed with signal 6
19 Runtime error 2 ms 332 KB Execution killed with signal 11
20 Runtime error 2 ms 460 KB Execution killed with signal 6