Submission #752918

# Submission time Handle Problem Language Result Execution time Memory
752918 2023-06-04T09:34:54 Z rahidilbayramli Garage (IOI09_garage) C++17
100 / 100
3 ms 352 KB
#include<bits/stdc++.h>
#define ll long long
#define ld long double
#define vl vector<ll>
#define vi vector<int>
#define pb push_back
#define all(v) v.begin(), v.end()
#define pii pair<int, int>
#define pll pair<ll, ll>
#define f first
#define s second
using namespace std;
int main()
{
    ll n, m, i, j, x, sum = 0;
    cin >> n >> m;
    ll rate[n+1], weight[m+1], spot[n+1], own[m+1];
    memset(spot, 0, sizeof(spot));
    memset(own, 0, sizeof(own));
    for(i = 1; i <= n; i++)    cin >> rate[i];
    for(i = 1; i <= m; i++)    cin >> weight[i];
    queue<ll>h;
    for(j = 1; j <= 2 * m; j++)
    {
        cin >> x;
        if(x > 0)
        {
            ll q = -1;
            for(i = 1; i <= n; i++)
            {
                if(spot[i] == 0)
                {
                    q = i;
                    break;
                }
            }
            if(q == -1)
                h.push(x);
            else
            {
                spot[q] = x;
                sum += rate[q] * weight[x];
                own[x] = q;
            }
        }
        else
        {
            x = -x;
            spot[own[x]] = 0;
            if(h.size())
            {
                ll p = h.front();
                own[p] = own[x];
                h.pop();
                spot[own[x]] = p;
                sum += weight[p] * rate[own[p]];
            }
        }
    }
    cout << sum << "\n";
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 300 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 1 ms 304 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 300 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 304 KB Output is correct
14 Correct 2 ms 308 KB Output is correct
15 Correct 2 ms 212 KB Output is correct
16 Correct 2 ms 212 KB Output is correct
17 Correct 2 ms 340 KB Output is correct
18 Correct 3 ms 352 KB Output is correct
19 Correct 2 ms 340 KB Output is correct
20 Correct 3 ms 340 KB Output is correct