답안 #233129

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
233129 2020-05-19T13:02:02 Z anubhavdhar Garage (IOI09_garage) C++14
50 / 100
1000 ms 2296 KB
#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[1001], R[101], W[1001];

	inline void dbg()
	{
		F0R(i, M)
			cerr<<"spot["<<i+1<<"] = "<<spot[i]+1<<'\n';
	}

	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, 1001)
			W[i] = w[i], spot[i] = -1;
		dbg();
	}

	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[1001];
	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;
		if(car > 0)
			myGar.entering(car-1);
		else
			myGar.exiting(-1-car);
		myGar.dbg();
	}
	// cout<<"done\n";
	myGar.reportAnswer();
	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 384 KB Output is correct
2 Correct 7 ms 384 KB Output is correct
3 Correct 5 ms 256 KB Output is correct
4 Correct 13 ms 256 KB Output is correct
5 Correct 10 ms 384 KB Output is correct
6 Correct 38 ms 384 KB Output is correct
7 Correct 14 ms 384 KB Output is correct
8 Correct 189 ms 632 KB Output is correct
9 Correct 52 ms 384 KB Output is correct
10 Correct 757 ms 1660 KB Output is correct
11 Execution timed out 1095 ms 2140 KB Time limit exceeded
12 Execution timed out 1090 ms 2296 KB Time limit exceeded
13 Execution timed out 1099 ms 2040 KB Time limit exceeded
14 Execution timed out 1090 ms 1976 KB Time limit exceeded
15 Execution timed out 1091 ms 2296 KB Time limit exceeded
16 Execution timed out 1098 ms 2168 KB Time limit exceeded
17 Execution timed out 1090 ms 2168 KB Time limit exceeded
18 Execution timed out 1098 ms 2296 KB Time limit exceeded
19 Runtime error 58 ms 636 KB Execution killed with signal 11 (could be triggered by violating memory limits)
20 Runtime error 25 ms 512 KB Execution killed with signal 11 (could be triggered by violating memory limits)