답안 #54166

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
54166 2018-07-02T14:45:09 Z hogogk(#1409) Garage (IOI09_garage) C++11
100 / 100
4 ms 752 KB
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
queue<int> wait;
priority_queue<int> parking;
int cost[1006],car[10007],weight[10006];
int main()
{
	int N,M; scanf("%d %d",&N,&M);
	ll ans=0;
	for(int i=1;i<=N;i++) parking.push(-i);
	for(int i=1;i<=N;i++) scanf("%d",&cost[i]);
	for(int i=1;i<=M;i++) scanf("%d",&weight[i]);
	for(int i=0;i<2*M;i++)
	{
		int t; scanf("%d",&t);
		if(t<0) parking.push(-car[-t]);
		else
		{
			if(parking.size()==0) wait.push(t);
			else
			{
				int v=-parking.top();
				parking.pop();
				car[t]=v; ans+=weight[t]*cost[v];
			}
		}
		while(!wait.empty() && !parking.empty())
		{
			int c1=wait.front(); wait.pop();
			int c2=-parking.top(); parking.pop();
			car[c1]=c2; ans+=cost[c2]*weight[c1];
		}
	}
	return !printf("%lld",ans);
}

Compilation message

garage.cpp: In function 'int main()':
garage.cpp:9:16: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  int N,M; scanf("%d %d",&N,&M);
           ~~~~~^~~~~~~~~~~~~~~
garage.cpp:12:29: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  for(int i=1;i<=N;i++) scanf("%d",&cost[i]);
                        ~~~~~^~~~~~~~~~~~~~~
garage.cpp:13:29: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  for(int i=1;i<=M;i++) scanf("%d",&weight[i]);
                        ~~~~~^~~~~~~~~~~~~~~~~
garage.cpp:16:15: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   int t; scanf("%d",&t);
          ~~~~~^~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 248 KB Output is correct
2 Correct 2 ms 360 KB Output is correct
3 Correct 2 ms 396 KB Output is correct
4 Correct 2 ms 472 KB Output is correct
5 Correct 3 ms 472 KB Output is correct
6 Correct 2 ms 472 KB Output is correct
7 Correct 3 ms 556 KB Output is correct
8 Correct 3 ms 556 KB Output is correct
9 Correct 2 ms 572 KB Output is correct
10 Correct 2 ms 572 KB Output is correct
11 Correct 3 ms 752 KB Output is correct
12 Correct 2 ms 752 KB Output is correct
13 Correct 2 ms 752 KB Output is correct
14 Correct 2 ms 752 KB Output is correct
15 Correct 2 ms 752 KB Output is correct
16 Correct 3 ms 752 KB Output is correct
17 Correct 4 ms 752 KB Output is correct
18 Correct 4 ms 752 KB Output is correct
19 Correct 3 ms 752 KB Output is correct
20 Correct 3 ms 752 KB Output is correct