Submission #973074

# Submission time Handle Problem Language Result Execution time Memory
973074 2024-05-01T13:24:15 Z Frigglet Garage (IOI09_garage) C++14
100 / 100
2 ms 600 KB
#include <algorithm>
#include <iostream>
#include <vector>
#include <numeric>
#include <utility>
#include <set>
#include <unordered_map>
#include <cmath>
#include <string.h>
#include <cctype>
#include <string>
using namespace std;
using ll = long long;
int main(){
    ll n, m;
    cin >> n >> m;
    ll rs, wk;
    ll a;
    vector<ll> rates;
    vector<ll> weights;
    vector<ll> occupied;
    unordered_map<ll,ll> spacemem;
    vector<ll> queue;
    for(int i=0; i<n; i++){
        occupied.push_back(0);
    }
    ll totalsum=0;
    ll counter=0;
    bool occupation=false;
    for(int i=0; i<n; i++){
        cin >> rs;
        rates.push_back(rs);
    }
    for(int i=0; i<m; i++){
        cin >> wk;
        weights.push_back(wk);
    }
    for(int i=0; i<m*2; i++){
        cin >> a;
        occupation = false;
        counter = 0;
        if(a>0){
            while(occupation==false){
                if(counter==n){
                    queue.push_back(a-1);
                    occupation=true;
                }
                else if(occupied[counter]==0){
                    occupation = true;
                    occupied[counter]=1;
                    spacemem[a-1]=counter;
                }
                else{
                    counter++;
                }
            }
            if(counter<n){
                totalsum += rates[counter]*weights[a-1];
            }
        }
        else{
            if(queue.size()>0){
                const auto leaving = abs(a) - 1;
                const auto coming = queue[0];
                totalsum += rates[spacemem[leaving]] * weights[coming];
                spacemem[queue[0]]=spacemem[abs(a)-1];
                queue.erase(queue.begin());
            }
            else{
                occupied[spacemem[abs(a)-1]]=0;
            }
        }
    }
    cout << totalsum;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 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 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 1 ms 344 KB Output is correct
10 Correct 0 ms 344 KB Output is correct
11 Correct 0 ms 600 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 2 ms 344 KB Output is correct
17 Correct 1 ms 412 KB Output is correct
18 Correct 2 ms 348 KB Output is correct
19 Correct 2 ms 348 KB Output is correct
20 Correct 2 ms 348 KB Output is correct