# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
297469 | aryan12 | Garage (IOI09_garage) | C++17 | 2 ms | 512 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
void Solve() {
long long spaces, cars;
cin >> spaces >> cars;
long long cost[spaces + 1], weight[cars + 1];
for(long long i = 1; i <= spaces; i++) {
cin >> cost[i];
}
for(long long i = 1; i <= cars; i++) {
cin >> weight[i];
}
unordered_map<long long, long long> Occupier;
// <car, space it has occupied>
set<long long> SpacesLeft;
for(long long i = 1; i <= spaces; i++) {
SpacesLeft.insert(i);
}
long long TotalCost = 0;
queue<long long> CarsWaiting;
for(long long i = 1; i <= 2 * cars; i++) {
long long operation;
cin >> operation;
if(operation > 0) {
if(SpacesLeft.size() == 0) {
CarsWaiting.push(operation);
}
else {
set<long long> :: iterator itr;
itr = SpacesLeft.begin();
long long pos = *itr;
Occupier[operation] = pos;
SpacesLeft.erase(pos);
TotalCost += (weight[operation] * cost[pos]);
}
}
else {
long long NewPos = Occupier[-operation];
Occupier[-operation] = -1;
if(CarsWaiting.empty())
SpacesLeft.insert(NewPos);
else {
long long Car = CarsWaiting.front();
Occupier[Car] = NewPos;
TotalCost += (weight[Car] * cost[NewPos]);
CarsWaiting.pop();
}
}
}
cout << TotalCost << "\n";
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
Solve();
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |