# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
393702 | Berted | Garage (IOI09_garage) | C++14 | 2 ms | 360 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <iostream>
#include <queue>
#include <assert.h>
using namespace std;
int N, M, A[101], B[2001];
int where[2001], filled[101], to = 0;
queue<int> q;
int res = 0;
int main()
{
ios :: sync_with_stdio(0); cin.tie(0); cout.tie(0);
cin >> N >> M;
for (int i = 0; i < N; i++) cin >> A[i];
for (int i = 0; i < M; i++)
{
where[i] = -1;
cin >> B[i];
}
for (int k = 0; k < 2 * M; k++)
{
int i; cin >> i;
if (i > 0)
{
i--;
if (to == N) {q.push(i);}
else
{
to++;
for (int j = 0; j < N; j++)
{
if (!filled[j]) {res += A[j] * B[i]; filled[j] = 1; where[i] = j; break;}
}
}
}
else
{
i = -i; i--;
filled[where[i]] = 0; to--;
if (q.size())
{
to++;
filled[where[i]] = 1; where[q.front()] = where[i];
res += A[where[i]] * B[q.front()]; q.pop();
}
}
}
cout << res << "\n";
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |