답안 #199841

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
199841 2020-02-03T16:04:10 Z aggu_01000101 Garage (IOI09_garage) C++14
100 / 100
7 ms 408 KB
#include <iostream>
#include <queue>
#define int long long
using namespace std;
int32_t main(){
    int n, m;
    cin>>n>>m;
    int rate[n];
    for(int i = 0;i<n;i++) cin>>rate[i];
    int w[m+1];
    for(int i = 1;i<=m;i++) cin>>w[i];
    int ans = 0;
    bool used[n];
    for(int i =0 ;i<n;i++) used[i] = false;
    queue<int> q;
    int val[m+1];
    for(int i = 1;i<=m;i++) val[i] = -1;
    int rev = 0;
    for(int i = 0;i<(2*m);i++){
        int x;
        cin>>x;
        if(x>0){
            q.push(x);
        }
        else{
            used[val[-x]] = false;
        }
        if(q.empty()) continue;
        for(int j = 0;j<n;j++){
            if(used[j]==false){
                //cout<<q.front()<<" "<<(j+1)<<" "<<rate[j]<<" "<<w[q.front()]<<endl;
                val[q.front()] = j;
                used[j] = true;
                rev+=(w[q.front()]*rate[j]);
                q.pop();
                goto last;
            }
        }
        last:
        continue;
        //cout<<rev<<endl;
    }
    cout<<rev<<endl;
}

Compilation message

garage.cpp: In function 'int32_t main()':
garage.cpp:12:9: warning: unused variable 'ans' [-Wunused-variable]
     int ans = 0;
         ^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 256 KB Output is correct
2 Correct 5 ms 256 KB Output is correct
3 Correct 5 ms 256 KB Output is correct
4 Correct 5 ms 248 KB Output is correct
5 Correct 6 ms 256 KB Output is correct
6 Correct 5 ms 248 KB Output is correct
7 Correct 5 ms 256 KB Output is correct
8 Correct 5 ms 256 KB Output is correct
9 Correct 5 ms 256 KB Output is correct
10 Correct 5 ms 256 KB Output is correct
11 Correct 5 ms 256 KB Output is correct
12 Correct 5 ms 376 KB Output is correct
13 Correct 5 ms 376 KB Output is correct
14 Correct 6 ms 376 KB Output is correct
15 Correct 6 ms 376 KB Output is correct
16 Correct 7 ms 376 KB Output is correct
17 Correct 7 ms 408 KB Output is correct
18 Correct 7 ms 376 KB Output is correct
19 Correct 7 ms 376 KB Output is correct
20 Correct 7 ms 376 KB Output is correct