답안 #275141

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
275141 2020-08-20T04:36:45 Z Bill_00 Garage (IOI09_garage) C++14
100 / 100
2 ms 384 KB
#include <bits/stdc++.h>
typedef long long ll;
const ll inf=1000000000000000000;
#define fr(i,c,d) for(ll i=c;i<=d;i++)
#define MOD 1000000007
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define pp push
using namespace std;
const int sz=173;
string str(string x,int l,int r){
	string h;
	for(int i=l;i<=r;i++){
		h+=x[i];
	}
	return h;
}
int main(){
	//int color[200001];
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	ll n,m;
	cin >> n >> m;
	ll a[101]={0},b[101];
	ll r[101];
	ll w[2001];
	for(int i=1;i<=n;i++){
		cin >> r[i];
	}
	for(int i=1;i<=m;i++){
		cin >> w[i];
	}
	ll ans=0;
	queue<ll>q;
	for(int i=1;i<=2*m;i++){
		ll car,flag=0;
		cin >> car;
		if(car>0){
			for(int j=1;j<=n;j++){
				if(a[j]==0){
					ans+=(w[car]*r[j]);
					a[j]=car;
					flag++;
					break;
				}
			}
			if(flag==0){
				q.pp(car);
			}
		}
		else{
			car=-car;
			for(int i=1;i<=n;i++){
				if(a[i]==car){
					a[i]=0;
				}
			}
			if(!q.empty()){
				for(int i=1;i<=n;i++){
					if(a[i]==0){
						a[i]=q.front();
						q.pop();
						ans+=(r[i]*w[a[i]]);
						break;
					}
				}
			}
		}
	}
	cout << ans;
}

Compilation message

garage.cpp: In function 'int main()':
garage.cpp:27:16: warning: unused variable 'b' [-Wunused-variable]
   27 |  ll a[101]={0},b[101];
      |                ^
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
13 Correct 1 ms 384 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
15 Correct 1 ms 384 KB Output is correct
16 Correct 2 ms 384 KB Output is correct
17 Correct 1 ms 384 KB Output is correct
18 Correct 2 ms 384 KB Output is correct
19 Correct 2 ms 384 KB Output is correct
20 Correct 2 ms 384 KB Output is correct