Submission #397591

# Submission time Handle Problem Language Result Execution time Memory
397591 2021-05-02T12:44:30 Z ak2006 Garage (IOI09_garage) C++14
100 / 100
3 ms 332 KB
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vb = vector<bool>;
using vvb = vector<vb>;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;
using vc = vector<char>;
using vvc = vector<vc>;
const ll mod = 1e9 + 7,inf = 1e18;
#define pb push_back
#define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
int main()
{
    int n,m;
    cin>>n>>m;
    vi r(n + 1),w(m + 1),ans(m + 1);
    vb taken(n + 1,false);
    vi pos(m + 1,-1);
    for (int i = 1;i<=n;i++)cin>>r[i];
    for (int i = 1;i<=m;i++)cin>>w[i];
    int x = 2 * m;
    queue<int>q;
    while (x--){
        int i;
        cin>>i;
        if (i < 0){
            i = -i;
            taken[pos[i]] = 0;
            while (!q.empty()){
                int cur = q.front();
                int index = -1;
                for (int j = 1;j<=n;j++){
                    if (!taken[j]){index = j;break;}
                }
                if (index == -1)break;
                pos[cur] = index;
                ans[cur] = r[index] * w[cur];
                taken[index] = 1;
                q.pop();
            }
        }
        else{
            for (int j = 1;j<=n;j++){
                if (!taken[j]){pos[i] = j;taken[j] = 1;ans[i] = r[j] * w[i];break;}
            }
            if (pos[i] == -1)
                q.push(i);
        }
    }
    ll tot = 0;
    for (int i = 1;i<=m;i++)tot += (ll)ans[i];
    cout<<tot;
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 300 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 324 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 296 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 300 KB Output is correct
12 Correct 1 ms 308 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Correct 1 ms 308 KB Output is correct
15 Correct 2 ms 312 KB Output is correct
16 Correct 2 ms 332 KB Output is correct
17 Correct 2 ms 332 KB Output is correct
18 Correct 3 ms 332 KB Output is correct
19 Correct 3 ms 332 KB Output is correct
20 Correct 3 ms 332 KB Output is correct