Submission #1119750

# Submission time Handle Problem Language Result Execution time Memory
1119750 2024-11-27T11:43:36 Z kasdo Garage (IOI09_garage) C++14
40 / 100
4 ms 596 KB
#include <bits/stdc++.h>
using namespace std;
#define int long long
signed main()
{
    int n, m;
    cin>>n>>m;
    int a[n + 5], b[m + 5];
    
    priority_queue<int> q;
    for(int i=1; i<=n; i++)
    {
        cin>>a[i];
        q.push(-i);
    }
    for(int i=1; i<=m; i++) cin>>b[i];
    
    int park[m + 5];
    vector<int> proc;
    int ans = 0;
    for(int i=1; i<=2*m; i++)
    {
        int x;
        cin>>x;
        
        if (x > 0) // join
        {
            if (q.size() > 0) // there is a parking
            {
                int cur = q.top();
                cur *= -1;
                
                park[x] = cur;
                ans += a[cur] * b[x];
                q.pop();
            }
            else // there is no parking
            {
                proc.push_back(x);
            }
        }
        else
        {
            q.push(-park[-x]);
            
            bool f = 0;
            if (q.size() > 0 && proc.size() > 0)
            {
                f = 1;
                reverse(proc.begin(), proc.end());
            }
            while(q.size() > 0 && proc.size() > 0)
            {
                int cur = q.top();
                cur *= -1;
                
                int idx = proc.back();
                
                // park[idx] = cur;
                ans += a[cur] * b[idx];
                q.pop();
                proc.pop_back();
            }
            if (f && proc.size() > 0) reverse(proc.begin(), proc.end());
        }
    }
    cout<<ans<<endl;
    
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 464 KB Output is correct
2 Runtime error 2 ms 556 KB Execution killed with signal 11
3 Correct 1 ms 344 KB Output is correct
4 Runtime error 2 ms 344 KB Execution killed with signal 11
5 Correct 1 ms 436 KB Output is correct
6 Runtime error 2 ms 444 KB Execution killed with signal 11
7 Correct 1 ms 344 KB Output is correct
8 Runtime error 2 ms 344 KB Execution killed with signal 11
9 Correct 1 ms 356 KB Output is correct
10 Runtime error 2 ms 468 KB Execution killed with signal 11
11 Correct 2 ms 444 KB Output is correct
12 Runtime error 2 ms 452 KB Execution killed with signal 11
13 Correct 2 ms 444 KB Output is correct
14 Runtime error 3 ms 512 KB Execution killed with signal 11
15 Correct 2 ms 480 KB Output is correct
16 Incorrect 3 ms 504 KB Output isn't correct
17 Runtime error 3 ms 468 KB Execution killed with signal 11
18 Runtime error 3 ms 592 KB Execution killed with signal 11
19 Runtime error 3 ms 448 KB Execution killed with signal 11
20 Runtime error 4 ms 596 KB Execution killed with signal 11