# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
953191 | DearSimone | Garage (IOI09_garage) | C++17 | 1 ms | 604 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include "bits/stdc++.h"
using namespace std;
typedef long long int64;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}
template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ", "; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? ", " : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifdef DEBUG
#define dbg(x...) cerr << "\e[91m"<<__func__<<":"<<__LINE__<<" [" << #x << "] = ["; _print(x); cerr << "\e[39m" << endl;
#else
#define dbg(x...)
#endif
const int MOD = 1000000007;
int indexFirstEmpty(const vector<int>& v) {
for (int i = 0; i < v.size(); i++) {
if (v[i] == -1)
return i;
}
return -1;
}
int indexOfCar(const vector<int>& v, int car) {
for (int i = 0; i < v.size(); i++) {
if (v[i] == car) {
return i;
}
}
return -1;
}
void solve() {
int spaces, cars;
cin >> spaces >> cars;
int ans = 0;
vector<int> parking(spaces, -1);
vector<int> rate_space(spaces);
vector<int> weight_cars(cars);
queue<int> line;
for (int i = 0; i < spaces; i++)
cin >> rate_space[i];
for (int i = 0; i < cars; i++)
cin >> weight_cars[i];
dbg(parking);
dbg(rate_space);
dbg(weight_cars);
for (int i = 0; i < 2*cars; i++) {
int curr_car; cin >> curr_car;
dbg(parking);
if (curr_car > 0) {
if (!line.empty()) {
line.push(curr_car);
continue;
}
int avail = indexFirstEmpty(parking);
if (avail == -1) {
line.push(curr_car);
continue;
}
ans += rate_space[avail] * weight_cars[curr_car-1];
parking[avail] = curr_car;
}
else {
// check if any car on queue and let it in
int new_empty = indexOfCar(parking, curr_car*-1);
parking[new_empty] = -1;
if (!line.empty()) {
ans += rate_space[new_empty] * weight_cars[line.front()-1];
parking[new_empty] = line.front();
line.pop();
}
}
}
cout << ans << '\n';
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
int T = 1;
while(T--) {
solve();
}
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |