Submission #233132

#TimeUsernameProblemLanguageResultExecution timeMemory
233132anubhavdharGarage (IOI09_garage)C++14
100 / 100
5 ms384 KiB
#include<bits/stdc++.h> #define ll long long int #define pb push_back #define mp make_pair #define FOR(i,n) for(i=0;i<(n);++i) #define FORe(i,n) for(i=1;i<=(n);++i) #define FORr(i,a,b) for(i=(a);i<(b);++i) #define FORrev(i,n) for(i=(n);i>=0;--i) #define F0R(i,n) for(int i=0;i<(n);++i) #define F0Re(i,n) for(int i=1;i<=(n);++i) #define F0Rr(i,a,b) for(ll i=(a);i<(b);++i) #define F0Rrev(i,n) for(int i=(n);i>=0;--i) #define ii pair<ll,ll> #define vi vector<ll> #define vii vector<ii> #define ff first #define ss second #define cd complex<double> #define vcd vector<cd> #define ldd long double #define dbgLine cout<<"Line : "<<__LINE__<<'\n' #define all(x) (x).begin(),(x).end() using namespace std; const short int __PRECISION = 10; const ll MOD = 1e9+7; const ll INF = 1e17 + 1101; const ll LOGN = 17; const ll MAXN = 2e5+5; const ll ROOTN = 320; const ldd PI = acos(-1); const ldd EPS = 1e-7; struct Garage { int N, M; ll ans; queue<int> WL; bool taken[101]; int spot[2020], R[101], W[2020]; Garage(int p, int q, int r[], int w[]) { N = p; M = q; ans = 0; F0R(i, 101) R[i] = r[i], taken[i] = false; F0R(i, 2020) W[i] = w[i], spot[i] = -1; } inline void entering(int car) { F0R(i, N) if(taken[i] == false) { taken[i] = true; spot[car] = i; ans += R[i]*W[car]; // cerr<<"car "<<car+1<<" to spot "<<i+1<<", cost "<<R[i]*W[car]<<'\n'; return; } WL.push(car); } inline void exiting(int car) { if(spot[car] > -1) { taken[spot[car]] = false; // cerr<<"removed car "<<car+1<<" from spot "<<spot[car] + 1<<'\n'; while(!WL.empty() and spot[WL.front()] == -2) WL.pop(); if(!WL.empty() and spot[WL.front()] == -1) { int car2 = WL.front(); WL.pop(); taken[spot[car]] = true; spot[car2] = spot[car]; ans += R[spot[car2]]*W[car2]; // cerr<<"car2 "<<car2+1<<" to spot "<<spot[car2]+1<<", cost "<<R[spot[car2]]*W[car2]<<'\n'; return; } } spot[car] = -2; } inline void reportAnswer() { cout << ans; } }; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int N, M, R[101], W[2020]; cin>>N>>M; F0R(i, N) cin>>R[i]; F0R(i, M) cin>>W[i]; Garage myGar(N, M, R, W); F0R(k, 2*M) { int car; cin>>car; (car > 0) ? myGar.entering(car-1) : myGar.exiting(-1-car); } // cout<<"done\n"; myGar.reportAnswer(); return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...