답안 #1096953

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1096953 2024-10-05T14:35:01 Z vjudge1 Garage (IOI09_garage) C++17
100 / 100
1 ms 452 KB
#include "bits/stdc++.h"
using namespace std;

#ifndef LOCAL
#define debug(...)
#endif

#define SZ(x)  ((int) x.size())
#define int    long long
#define vvi    vector<vector<int>>
#define endl  '\n'
#define pii    pair<int, int>
#define all(v) (v).begin(), (v).end()

template <typename T>
istream &operator>>(istream& is,  vector<T> &v) {
    for (auto &x: v) is >> x;
    return is;
}


void run_test() {
    int n, m;
    cin >> n >> m;
    vector<int> rate(n+1), wt(m+1);
    for (int i = 1; i <= n; i++) cin >> rate[i];
    for (int i = 1; i <= m; i++) cin >> wt[i];

    vector<int> ad(2*m);
    cin >> ad;

    vector<int> garage(n+1, -1);
    queue<int> q;
    int ans = 0;
    for (int i = 0; i < 2*m; i++) {
        int car = ad[i];
        if (car < 0) {
            for (int j = 1; j <= n; j++) {
                if (garage[j] == -car) {
                    garage[j] = -1;
                    break;
                }
            }
        } 
        if (car > 0) q.push(car);
        if (q.empty()) continue;
        int top = q.front();
        bool parked = false;
        for (int j = 1; j <= n; j++) {
            if (garage[j] == -1) {
                parked = true;
                garage[j] = top;
                ans += wt[top] * rate[j];
                break;
            }
        }
        if (parked) q.pop();
    }
    cout << ans << endl;
}

int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    int tc = 1;
    // cin >> tc;
    while (tc--) {
        run_test();
    }
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 452 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 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 348 KB Output is correct
20 Correct 1 ms 348 KB Output is correct