답안 #862864

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
862864 2023-10-19T07:07:23 Z nasir_bashirov Garage (IOI09_garage) C++11
100 / 100
1 ms 464 KB
#include <bits/stdc++.h>
#define intt long long
#define pb push_back
#define pii pair<int,int>
#define pll pair<intt,intt>
#define F first
#define S second
#define endl '\n'
#define sync                          \
	ios_base::sync_with_stdio(0);     \
	cin.tie(0);                       \
	cout.tie(0)
using namespace std;
int rates[105],cars[2005],owner[2005];
set<pii>st;
int main() {
    sync;
    int n,m,res;
    cin >> n >> m;
    for(int i=1;i<=n;i++){
        cin >> rates[i];
    }
    for(int i=1;i<=m;i++){
        cin >> cars[i];
    }
    res = 0;
    queue<int>q;
    set<int>free_space;
    for(int i=1;i<=n;i++){
        free_space.insert(i);
    }
    m *= 2;
    int x;
    // queue<int>q;
    while(m--){
        cin >> x;
        if(x > 0){
           if(free_space.empty()){
                q.push(x);
                continue;
           }
           auto it = free_space.begin();
           int place = *it;
           owner[x] = place;
           free_space.erase(it);
           res += rates[place] * cars[x];
        }
        else{
            x = -x;
            int oww = owner[x];
            //owner[x] = 0;
            if(q.empty()){
                free_space.insert(oww);
            }
            else{
                int first = q.front();
                q.pop();
                owner[first] = oww;
                res += cars[first] * rates[oww];
            }
        }
    }
    cout << res;
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 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 1 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 1 ms 344 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 1 ms 464 KB Output is correct
19 Correct 1 ms 344 KB Output is correct
20 Correct 1 ms 348 KB Output is correct