답안 #120094

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
120094 2019-06-23T10:22:39 Z Boxworld Garage (IOI09_garage) C++14
100 / 100
3 ms 512 KB
#include <bits/stdc++.h>
using namespace std;
const int N=5100;
int x,n,m,r[N],w[N],a[N],ans=0;
priority_queue<int,vector<int>,greater<int> > pQ;//parklot
queue<int> wQ;//waiting
char s[N];
int main(){
	scanf("%d%d",&m,&n);
	for (int i=1;i<=m;i++)scanf("%d",&r[i]);
	for (int i=1;i<=n;i++)scanf("%d",&w[i]);
	for (int i=1;i<=m;i++)pQ.push(i);
	for (int i=1;i<=n*2;i++){
		scanf("%d",&x);
		if (x<0){
			x*=-1;
			if (wQ.empty())pQ.push(a[x]);
			else{int y=wQ.front();wQ.pop();a[y]=a[x];}
		}else{
			if (pQ.empty())wQ.push(x);
			else {a[x]=pQ.top();pQ.pop();}
		}
	}
	for (int i=1;i<=n;i++)ans+=r[a[i]]*w[i];
	printf("%d\n",ans);
}

Compilation message

garage.cpp: In function 'int main()':
garage.cpp:9:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d%d",&m,&n);
  ~~~~~^~~~~~~~~~~~~~
garage.cpp:10: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",&r[i]);
                        ~~~~~^~~~~~~~~~~~
garage.cpp:11: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",&w[i]);
                        ~~~~~^~~~~~~~~~~~
garage.cpp:14:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d",&x);
   ~~~~~^~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
3 Correct 2 ms 512 KB Output is correct
4 Correct 2 ms 384 KB Output is correct
5 Correct 2 ms 384 KB Output is correct
6 Correct 2 ms 384 KB Output is correct
7 Correct 2 ms 256 KB Output is correct
8 Correct 2 ms 256 KB Output is correct
9 Correct 2 ms 384 KB Output is correct
10 Correct 2 ms 256 KB Output is correct
11 Correct 2 ms 384 KB Output is correct
12 Correct 3 ms 384 KB Output is correct
13 Correct 2 ms 384 KB Output is correct
14 Correct 2 ms 256 KB Output is correct
15 Correct 2 ms 384 KB Output is correct
16 Correct 3 ms 384 KB Output is correct
17 Correct 3 ms 384 KB Output is correct
18 Correct 3 ms 384 KB Output is correct
19 Correct 3 ms 384 KB Output is correct
20 Correct 3 ms 384 KB Output is correct