# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
545583 | pere_gil | Garage (IOI09_garage) | C++17 | 1 ms | 340 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 ll;
int main(){
ll n,m; scanf("%lld %lld",&n,&m);
vector<ll> r(n+1);
for(ll i=1;i<=n;i++) scanf("%lld",&r[i]);
vector<ll> h(m+1);
for(ll i=1;i<=m;i++) scanf("%lld",&h[i]);
queue<ll> car;
stack<ll> place;
ll res=0;
for(ll i=n;i>0;i--) place.push(i);
vector<ll> v(m+1);
for(ll i=0;i<2*m;i++){
ll act; scanf("%lld",&act);
if(act>0){
if(place.empty()) car.push(act);
else{
v[act]=place.top();
//prllf("putting car %d in %d so + %d * %d -> %d\n",act,place.top(),h[act],r[v[act]],h[act]*r[v[act]]);
res+=h[act]*r[v[act]];
place.pop();
}
}
else{
place.push(v[-act]);
if(!car.empty()){
v[car.front()]=place.top();
//prllf("r putting car %d in %d so + %d * %d -> %d\n",car.front(),place.top(),h[car.front()],r[v[car.front()]],h[car.front()]*r[v[car.front()]]);
res+=h[car.front()]*r[v[car.front()]];
place.pop();
car.pop();
}
}
}
printf("%lld\n",res);
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |