# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
752918 | rahidilbayramli | Garage (IOI09_garage) | C++17 | 3 ms | 352 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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 |
---|---|---|---|---|
Fetching results... |