Submission #57797

# Submission time Handle Problem Language Result Execution time Memory
57797 2018-07-16T07:35:03 Z gnoor Garage (IOI09_garage) C++17
100 / 100
5 ms 808 KB
#include <cstdio>
#include <vector>
#include <algorithm>
#include <queue>

using namespace std;

int rate[500];
int wgt[2010];

struct Rint {
	bool operator()(const int &a, const int &b) {
		return a>b;
	}
};

priority_queue<int,vector<int>,Rint> q;
int park[2010];

int main () {
	int n,m;
	scanf("%d%d",&n,&m);
	for (int i=1;i<=n;i++) {
		scanf("%d",&rate[i]);
		q.push(i);
	}
	for (int i=1;i<=m;i++) {
		scanf("%d",&wgt[i]);
	}
	int x;
	long long ans=0;
	queue<int> car;
	for (int i=0;i<2*m;i++) {
		scanf("%d",&x);
		if (x>0) {
			car.push(x);
		} else {
			q.push(park[-x]);
			park[-x]=0;
		}
		while (!q.empty()&&!car.empty()) {
			ans+=(long long)wgt[car.front()]*rate[q.top()];
			park[car.front()]=q.top();
			car.pop();
			q.pop();
		}
	}
	printf("%lld\n",ans);
	return 0;
}

Compilation message

garage.cpp: In function 'int main()':
garage.cpp:22:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d%d",&n,&m);
  ~~~~~^~~~~~~~~~~~~~
garage.cpp:24:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d",&rate[i]);
   ~~~~~^~~~~~~~~~~~~~~
garage.cpp:28:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d",&wgt[i]);
   ~~~~~^~~~~~~~~~~~~~
garage.cpp:34:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d",&x);
   ~~~~~^~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 3 ms 376 KB Output is correct
2 Correct 3 ms 376 KB Output is correct
3 Correct 2 ms 420 KB Output is correct
4 Correct 3 ms 584 KB Output is correct
5 Correct 2 ms 584 KB Output is correct
6 Correct 2 ms 664 KB Output is correct
7 Correct 3 ms 664 KB Output is correct
8 Correct 3 ms 664 KB Output is correct
9 Correct 2 ms 664 KB Output is correct
10 Correct 2 ms 664 KB Output is correct
11 Correct 3 ms 664 KB Output is correct
12 Correct 2 ms 768 KB Output is correct
13 Correct 3 ms 768 KB Output is correct
14 Correct 2 ms 768 KB Output is correct
15 Correct 3 ms 768 KB Output is correct
16 Correct 4 ms 768 KB Output is correct
17 Correct 5 ms 768 KB Output is correct
18 Correct 4 ms 772 KB Output is correct
19 Correct 4 ms 784 KB Output is correct
20 Correct 5 ms 808 KB Output is correct