답안 #924800

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
924800 2024-02-09T17:04:38 Z boris_mihov Garage (IOI09_garage) C++17
100 / 100
1 ms 460 KB
#include <algorithm>
#include <iostream>
#include <numeric>
#include <cassert>
#include <vector>
#include <queue>
#include <set>

typedef long long llong;
const int MAXN = 2000 + 10;
const int INF  = 1e9;

int n, m, p;
int r[MAXN];
int w[MAXN];
int at[MAXN];
int takenBy[MAXN];
std::queue <int> q;
std::set <int> avaliable;

void solve()
{
    for (int i = 1 ; i <= n ; ++i)
    {
        avaliable.insert(i);
    }

    int ans = 0;
    for (int i = 1 ; i <= 2 * m ; ++i)
    {
        int idx;
        std::cin >> idx;

        if (idx > 0)
        {
            q.push(idx);
        } else
        {
            idx = -idx;
            takenBy[at[idx]] = 0;
            avaliable.insert(at[idx]);
        }

        while (avaliable.size() && q.size())
        {
            int front = q.front();
            q.pop();
        
            ans += r[*avaliable.begin()] * w[front];
            takenBy[*avaliable.begin()] = front;
            at[front] = *avaliable.begin();

            avaliable.erase(avaliable.begin());
        }        
    }
    
    std::cout << ans << '\n';
}

void input()
{
    std::cin >> n >> m;
    for (int i = 1 ; i <= n ; ++i)
    {
        std::cin >> r[i];
    }

    for (int i = 1 ; i <= m ; ++i)
    {
        std::cin >> w[i];
    }
}

void fastIOI()
{
    std::ios_base :: sync_with_stdio(0);
    std::cout.tie(nullptr);
    std::cin.tie(nullptr);
}   

int main()
{
    fastIOI();
    input();
    solve();

    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 460 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 0 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 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 1 ms 344 KB Output is correct
13 Correct 0 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 1 ms 348 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 1 ms 348 KB Output is correct