답안 #440321

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
440321 2021-07-02T04:32:28 Z dxz05 Garage (IOI09_garage) C++14
100 / 100
3 ms 332 KB
#include <bits/stdc++.h>

using namespace std;

const int MAXN = 2022;

int s[MAXN], w[MAXN];
int garage[MAXN];

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

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

    long long ans = 0;

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

        if (x > 0){
            q.push(x);
            for (int i = 1; i <= n; i++){
                if (garage[i] == 0){
                    garage[i] = x;
                    ans += w[x] * s[i];
                    q.pop();
                    break;
                }
            }
        } else {
            x = -x;
            for (int i = 1; i <= n; i++){
                if (garage[i] == x){
                    if (!q.empty()) {
                        garage[i] = q.front();
                        ans += w[q.front()] * s[i];
                        q.pop();
                    } else garage[i] = 0;
                    break;
                }
            }
        }

    }

    cout << ans;

    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 292 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 296 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 1 ms 300 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 2 ms 204 KB Output is correct
16 Correct 2 ms 204 KB Output is correct
17 Correct 3 ms 332 KB Output is correct
18 Correct 3 ms 332 KB Output is correct
19 Correct 3 ms 332 KB Output is correct
20 Correct 3 ms 332 KB Output is correct