답안 #715369

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
715369 2023-03-26T14:55:05 Z Toxtaq Garage (IOI09_garage) C++17
100 / 100
3 ms 340 KB
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int spaces, cars;
    long long result = 0;
    cin >> spaces >> cars;
    vector<int>rate(spaces + 1), weights(cars + 1);
    for(int i = 1;i <= spaces;++i)cin >> rate[i];
    for(int i = 1;i <= cars;++i)cin >> weights[i];
    vector<int>parking(spaces + 1);
    queue<int>q;
    for(int i = 0;i < 2 * cars;++i){
        int car;
        bool parked = false;
        cin >> car;
        if(car > 0){
            for(int j = 1;j <= spaces;++j){
                if(!parking[j]){
                    parking[j] = car;
                    result += weights[car] * rate[j];
                    parked = true;
                    break;
                }
            }
            if(!parked){
                q.push(car);
            }
        }
        else{
            for(int j = 1;j <= spaces;++j){
                if(-car == parking[j]){
                    parking[j] = 0;
                    break;
                }
            }
            if(!q.empty()){
                int cur = q.front();
                q.pop();
                for(int j = 1;j <= spaces;++j){
                    if(!parking[j]){
                        parking[j] = cur;
                        result += weights[cur] * rate[j];
                        break;
                    }
                }
            }
        }
    }
    cout << result;
}
# 결과 실행 시간 메모리 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 300 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 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 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 2 ms 212 KB Output is correct
17 Correct 2 ms 212 KB Output is correct
18 Correct 2 ms 340 KB Output is correct
19 Correct 3 ms 340 KB Output is correct
20 Correct 2 ms 212 KB Output is correct