답안 #858692

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
858692 2023-10-09T04:42:55 Z aykhn Garage (IOI09_garage) C++14
100 / 100
1 ms 456 KB
#include <bits/stdc++.h>

// author : aykhn

using namespace std;
typedef long long ll;

#define pb push_back
#define ins insert
#define mpr make_pair
#define all(v) v.begin(), v.end()
#define bpc __builtin_popcount
#define pii pair<int, int>
#define pll pair<ll, ll>
#define fi first
#define se second
#define int ll
#define infll 0x3F3F3F3F3F3F3F3F
#define inf 0x3F3F3F3F

const int MXN = 1e4 + 5;

int n, m;
int r[MXN], w[MXN], id[MXN];
queue<int> q;
set<int> s;
int res;

void _()
{
    cin >> n >> m;
    for (int i = 1; i <= n; i++) cin >> r[i];
    for (int i = 1; i <= m; i++) cin >> w[i];
    for (int i = 1; i <= n; i++) s.ins(i);
    for (int i = 1; i <= 2*m; i++)
    {
        int x;
        cin >> x;
        if (x < 0)
        {
            if (q.empty()) 
            {
                s.ins(id[-x]);
                continue;
            }
            int y = q.front();
            q.pop();
            id[y] = id[-x];
            id[-x] = 0; 
            res += r[id[y]] * w[y]; 
            continue;
        }
        if (s.empty())
        {
            q.push(x);
            continue;
        }
        id[x] = *s.begin();
        s.erase(s.begin());
        res += r[id[x]] * w[x];
    }
    cout << res << '\n';
}

signed main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int t = 1;
    //cin >> t;
    for (int i = 1; i <= t; i++)
    {
        _();
    }
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 456 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 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 0 ms 348 KB Output is correct
14 Correct 1 ms 344 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