답안 #758953

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
758953 2023-06-15T15:12:32 Z raysh07 Garage (IOI09_garage) C++17
100 / 100
1 ms 340 KB
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define INF (int)1e18
#define f first
#define s second

mt19937_64 RNG(chrono::steady_clock::now().time_since_epoch().count());
int n, m;
int a[101];
int w[2001];
int ass[2001];

void Solve() 
{
    cin >> n >> m;
    int ans = 0;
    set <int> av;
    for (int i = 1; i <= n; i++){
        av.insert(i);
        cin >> a[i];
    }
    
    for (int i = 1; i <= m; i++) cin >> w[i];
    
    queue <int> q;
    for (int i = 1; i <= 2 * m; i++){
        int x; cin >> x;
        
        if (x > 0){
            if (av.size()){
                int u = *av.begin();
                ans += a[u] * w[x];
                ass[x] = u;
                av.erase(u);
            } else {
                q.push(x);
            }
        } else {
            x = -x;
            
            if (q.size()){
                int y = q.front();
                int u = ass[x];
                ass[y] = u;
                ans += a[u] * w[y];
                q.pop();
            } else {
                av.insert(ass[x]);
            }
        }
    }
    
    cout << ans << "\n";
}

int32_t main() 
{
    auto begin = std::chrono::high_resolution_clock::now();
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int t = 1;
  //  cin >> t;
    for(int i = 1; i <= t; i++) 
    {
        //cout << "Case #" << i << ": ";
        Solve();
    }
    auto end = std::chrono::high_resolution_clock::now();
    auto elapsed = std::chrono::duration_cast<std::chrono::nanoseconds>(end - begin);
    cerr << "Time measured: " << elapsed.count() * 1e-9 << " seconds.\n"; 
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 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 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 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct