답안 #76072

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
76072 2018-09-12T03:23:47 Z luciocf Garage (IOI09_garage) C++14
100 / 100
5 ms 1268 KB
// IOI 2009 - Garage
// Lúcio Cardoso

#include <bits/stdc++.h>

using namespace std;

const int MAXN = 110;
const int MAXM = 2010;

int num[MAXM], peso[MAXM], custo[MAXN];
bool ocupado[MAXN];

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

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

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

        if (x > 0)
        {
            bool flag = 0;
            for (int i = 1; i <= n; i++)
            {
                if (!ocupado[i])
                {
                    ocupado[i] = 1;
                    flag = 1;
                    ans += peso[x]*custo[i];
                    num[x] = i;
                    break;
                }
            }
            if (!flag) fila.push(x);
        }
        else
        {
            x = -x;
            ocupado[num[x]] = 0;

            if (fila.size() > 0)
            {
                num[fila.front()] = num[x];
                ans += custo[num[x]]*peso[fila.front()];
                fila.pop();
                ocupado[num[x]] = 1;
            }
        }
    }
    cout << ans << "\n";
}
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 504 KB Output is correct
2 Correct 2 ms 668 KB Output is correct
3 Correct 2 ms 748 KB Output is correct
4 Correct 2 ms 748 KB Output is correct
5 Correct 2 ms 876 KB Output is correct
6 Correct 2 ms 876 KB Output is correct
7 Correct 3 ms 876 KB Output is correct
8 Correct 3 ms 876 KB Output is correct
9 Correct 2 ms 876 KB Output is correct
10 Correct 2 ms 876 KB Output is correct
11 Correct 3 ms 876 KB Output is correct
12 Correct 3 ms 956 KB Output is correct
13 Correct 2 ms 956 KB Output is correct
14 Correct 3 ms 956 KB Output is correct
15 Correct 3 ms 956 KB Output is correct
16 Correct 3 ms 956 KB Output is correct
17 Correct 4 ms 956 KB Output is correct
18 Correct 4 ms 1016 KB Output is correct
19 Correct 4 ms 1268 KB Output is correct
20 Correct 5 ms 1268 KB Output is correct