답안 #697750

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
697750 2023-02-11T03:10:29 Z hiikunZ Garage (IOI09_garage) C++17
100 / 100
2 ms 340 KB
#include<bits/stdc++.h>
using namespace std;
using ll = long long int;
int main(){
    ll N,M;
    cin >> N >> M;
    vector<ll> R(N),W(M),U(N,0),P(M,-1);
    ll ans = 0;
    for(ll i = 0;i < N;i++) cin >> R[i];
    for(ll i = 0;i < M;i++) cin >> W[i];
    queue<ll> que;
    for(ll q = 0;q < M * 2;q++){
        ll s;
        cin >> s;
        if(s > 0){
            s--;
            que.emplace(s);
        }
        else{
            s *= -1;
            s--;
            U[P[s]] = 0;
        }
        while(!que.empty()){
            ll ok = 0;
            for(ll i = 0;i < N;i++){
                if(U[i] == 0){
                    U[i] = 1;
                    P[que.front()] = i;
                    ans += R[i] * W[que.front()];
                    que.pop();
                    ok = 1;
                    break;
                }
            }
            if(!ok) break;
        }
    }
    cout << ans << endl;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 300 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 300 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 308 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 2 ms 340 KB Output is correct
18 Correct 2 ms 340 KB Output is correct
19 Correct 2 ms 340 KB Output is correct
20 Correct 2 ms 340 KB Output is correct