답안 #697666

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
697666 2023-02-10T17:11:31 Z europium Garage (IOI09_garage) C++17
100 / 100
2 ms 340 KB
// - 11/2/23
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <numeric>
#include <cmath>
#include <iterator>
#include <set>
#include <map>
#include <math.h>
#include <iomanip>
#include <unordered_set>
#include <queue>
#include <climits>
using namespace std;
// clang++ -std=c++17 IOI09_Garage.cpp && ./a.out

using ll = long long;

void solve(){
    int n, m;
    cin >> n >> m;

    vector<int> r(n), w(m), p(n);
    for (int& e : r) cin >> e;
    for (int& e : w) cin >> e;

    int ans = 0, free = n;
    queue<int> q;

    for (int t = 0; t < 2 * m; t++){
        int e;
        cin >> e;

        if (e > 0){
            if (free == 0){
                q.push(e);
            }
            else{
                free--;

                for (int i = 0; i < n; i++){
                    if (p[i] == 0){
                        p[i] = e;
                        ans += r[i] * w[e - 1];
                        break;
                    }
                }
            }
        }
        else{
            for (int i = 0; i < n; i++){
                if (p[i] == abs(e)){
                    if (q.empty()){
                        free++;
                        p[i] = 0;
                    }
                    else{
                        int e = q.front();
                        p[i] = e;
                        ans += r[i] * w[e - 1];
                        q.pop();
                    }
                }
            }
        }
    }

    cout << ans;
    cout << '\n';
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);

    // freopen("input.txt", "r", stdin);
    solve();

    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 324 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 0 ms 328 KB Output is correct
7 Correct 1 ms 316 KB Output is correct
8 Correct 0 ms 320 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 328 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 328 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 332 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 2 ms 332 KB Output is correct
20 Correct 1 ms 332 KB Output is correct