답안 #300249

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
300249 2020-09-17T03:02:38 Z fpc_coder Garage (IOI09_garage) C++17
100 / 100
4 ms 512 KB
#include <bits/stdc++.h>

using namespace std;

const int N = 105;
const int M = 2005;
int w[M], r[N], pos[M];

int main() {
    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];
    queue<int> wait;
    vector<int> empty_pos(n);
    for (int i = 0; i < n; i++) empty_pos[i] = i + 1;
    int ans = 0;
    for (int i = 0; i < 2 * m; i++) {
        int car;
        cin >> car;
        if (car > 0) {
            if (!empty_pos.empty()) {
                vector<int>::iterator mn_it = min_element(empty_pos.begin(), empty_pos.end());
                int mn_pos = *mn_it;
                ans += w[car] * r[mn_pos];
                pos[car] = mn_pos;
                empty_pos.erase(mn_it);
            }
            else wait.push(car);
        }
        else {
            car = -car;
            if (!wait.empty()) {
                int waiting = wait.front(); wait.pop();
                pos[waiting] = pos[car];
                ans += w[waiting] * r[pos[waiting]];
            }
            else empty_pos.push_back(pos[car]);
        }
    }    
    cout << ans << '\n';
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 256 KB Output is correct
2 Correct 1 ms 256 KB Output is correct
3 Correct 1 ms 256 KB Output is correct
4 Correct 1 ms 256 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 1 ms 256 KB Output is correct
9 Correct 1 ms 256 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 1 ms 512 KB Output is correct
12 Correct 2 ms 384 KB Output is correct
13 Correct 2 ms 384 KB Output is correct
14 Correct 2 ms 512 KB Output is correct
15 Correct 2 ms 384 KB Output is correct
16 Correct 3 ms 384 KB Output is correct
17 Correct 3 ms 384 KB Output is correct
18 Correct 3 ms 384 KB Output is correct
19 Correct 3 ms 384 KB Output is correct
20 Correct 4 ms 384 KB Output is correct