답안 #518592

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
518592 2022-01-24T08:55:43 Z blue Garage (IOI09_garage) C++17
100 / 100
3 ms 332 KB
#include <iostream>
#include <set>
#include <queue>
using namespace std;

int main()
{
    int N, M;
    cin >> N >> M;
    
    int R[N+1];
    for(int i = 1; i <= N; i++) cin >> R[i];
    
    int W[M+1];
    for(int i = 1; i <= M; i++) cin >> W[i];
    
    queue<int> Q;
    set<int> S;
    for(int i = 1; i <= N; i++) S.insert(i);
    
    int res = 0;
    int a;
    
    int P[M+1];
    
    for(int i = 1; i <= 2*M; i++)
    {
        cin >> a;
        if(a > 0) Q.push(a);
        else S.insert(P[-1*a]);
        
        while(!Q.empty() && !S.empty())
        {
            P[Q.front()] = *S.begin();
            res += W[Q.front()] * R[*S.begin()];
            S.erase(*S.begin());
            Q.pop();
        }
    }
    cout << res << '\n';
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 272 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 292 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 0 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 292 KB Output is correct
12 Correct 1 ms 300 KB Output is correct
13 Correct 1 ms 300 KB Output is correct
14 Correct 1 ms 304 KB Output is correct
15 Correct 1 ms 308 KB Output is correct
16 Correct 2 ms 308 KB Output is correct
17 Correct 2 ms 332 KB Output is correct
18 Correct 3 ms 332 KB Output is correct
19 Correct 2 ms 320 KB Output is correct
20 Correct 2 ms 332 KB Output is correct