Submission #853945

# Submission time Handle Problem Language Result Execution time Memory
853945 2023-09-25T15:31:50 Z tue147 Garage (IOI09_garage) C++14
100 / 100
2 ms 476 KB
# include <bits/stdc++.h>
using namespace std;

int n,m;
unsigned long long sum = 0;

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

    cin >> n >> m;
    int r[n];
    int w[m];
    set<int> s;
    unordered_map<int, int> store;
    queue<int> q;
    int temp;
    for (int i=0; i< n; i++){
        cin >> r[i];
        s.insert(i);
    }
    for (int i=0; i< m; i++){
        cin >> w[i];
    }
    for (int i=0; i< 2*m; i++){
        cin >> temp;
        if (temp > 0){
            if (!s.empty()){
                set<int>::iterator ptr = s.begin();
                sum += r[*ptr] * w[temp-1];
                store[temp] = *ptr;
                s.erase(ptr);
            }
            else{
                q.push(temp);
            }
        }
        else{
            temp = -temp;
            int place = store[temp];
            s.insert(place);
            store.erase(temp);
        }
        while (!q.empty() && !s.empty()){
            temp = q.front();
            q.pop();
            set<int>::iterator ptr = s.begin();
            sum += r[*ptr] * w[temp-1];
            store[temp] = *ptr;
            s.erase(ptr);
        }
    }
    cout << sum;
    return 0;
}

Compilation message

garage.cpp: In function 'int main()':
garage.cpp:8:15: warning: statement is a reference, not call, to function 'std::ios_base::sync_with_stdio' [-Waddress]
    8 |     ios_base::sync_with_stdio;
      |     ~~~~~~~~~~^~~~~~~~~~~~~~~
garage.cpp:8:15: warning: statement has no effect [-Wunused-value]
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 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 344 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 1 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 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 1 ms 440 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 348 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 2 ms 476 KB Output is correct
20 Correct 2 ms 348 KB Output is correct