Submission #233131

# Submission time Handle Problem Language Result Execution time Memory
233131 2020-05-19T13:05:17 Z anubhavdhar Garage (IOI09_garage) C++14
100 / 100
6 ms 512 KB
#include<bits/stdc++.h>

#define ll long long
#define int ll
#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[2002], R[101], W[2002];

	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, 2002)
			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;
	}


};

signed main()
{
	
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	
	int N, M, R[101], W[2002];
	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 time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 4 ms 384 KB Output is correct
3 Correct 4 ms 384 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 4 ms 384 KB Output is correct
7 Correct 5 ms 384 KB Output is correct
8 Correct 5 ms 384 KB Output is correct
9 Correct 5 ms 384 KB Output is correct
10 Correct 5 ms 384 KB Output is correct
11 Correct 5 ms 384 KB Output is correct
12 Correct 5 ms 384 KB Output is correct
13 Correct 5 ms 384 KB Output is correct
14 Correct 5 ms 384 KB Output is correct
15 Correct 5 ms 384 KB Output is correct
16 Correct 5 ms 384 KB Output is correct
17 Correct 5 ms 384 KB Output is correct
18 Correct 5 ms 384 KB Output is correct
19 Correct 6 ms 512 KB Output is correct
20 Correct 5 ms 384 KB Output is correct