Submission #675891

# Submission time Handle Problem Language Result Execution time Memory
675891 2022-12-28T09:54:16 Z Cookie Garage (IOI09_garage) C++14
100 / 100
2 ms 340 KB
#include<bits/stdc++.h>

#include<fstream>

using namespace std;
//ifstream fin("INTERNET.INP");
//ofstream fout("INTERNET.OUT");
#define ll long long
#define vt vector
#define pb push_back
#define fi first
#define se second
#define forr(i, a, b) for(int i = a; i < b; i++)
#define dorr(i, a, b) for(int i = a; i >= b; i--)
#define pii pair<int, int>
#define pll pair<ll, ll>
//#define int long long
typedef unsigned long long ull;
const int mxn = 2e3, sq = 317, mxv = 1e4;
const ll mx = 1e9;
const ll p[4] = {2, 3, 5, 7};
int n, m;
int r[mxn + 1], w[mxn + 1], pos[mxn + 1];
set<int>s;
queue<int>q;
signed main()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    cin >> n >> m;
    for(int i = 1; i <= n; i++){
        cin >> r[i]; s.insert(i);
    }
    int ans = 0;
    for(int i = 1; i <= m; i++)cin >> w[i];
    for(int i = 0; i < 2 * m; i++){
        int x; cin >> x;
        if(x > 0){
            if(s.size()){
                int p = *s.begin(); s.erase(p); pos[x] = p;
                ans += w[x] * r[p];
            }else{
                q.push(x);
            }
        }else{
            x = -x; int nw = pos[x];
            if(q.size()){
                int cr = q.front(); q.pop(); pos[cr] = nw; ans += w[cr] * r[nw];
            }else{
                s.insert(nw);
            }
        }
        
    }
    cout << ans;
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 320 KB Output is correct
3 Correct 0 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 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 324 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 340 KB Output is correct
12 Correct 0 ms 324 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 336 KB Output is correct
19 Correct 2 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct