Submission #53452

# Submission time Handle Problem Language Result Execution time Memory
53452 2018-06-30T04:49:58 Z 장홍준(#2017) Garage (IOI09_garage) C++11
100 / 100
4 ms 620 KB
#include<stdio.h>
#include<queue>
#include<deque>
using namespace std;
priority_queue<int>H; deque<int>Q;
int qr[4141], C[212], W[4141], V[4141];
int main() {
	int i, j, n, m, ans = 0; scanf("%d%d", &n, &m);
	for (i = 1; i <= n; i++)H.push(-i), scanf("%d", &C[i]);
	for (i = 1; i <= m; i++)scanf("%d", &V[i]);
	for (i = 0; i < m * 2; i++) {
		int x; scanf("%d", &x);
		if (x > 0) {
			if (H.empty())Q.push_back(x);
			else W[x] = -H.top(), H.pop(), ans += C[W[x]] * V[x];
		}
		else {
			x = -x;
			if(Q.empty()) H.push(-W[x]);
			else {
				int now = Q.front(); Q.pop_front();
				W[now] = W[x]; W[x] = 0; ans += C[W[now]] * V[now];
			}
		}
	}
	printf("%d", ans);
	return 0;
}

Compilation message

garage.cpp: In function 'int main()':
garage.cpp:8:9: warning: unused variable 'j' [-Wunused-variable]
  int i, j, n, m, ans = 0; scanf("%d%d", &n, &m);
         ^
garage.cpp:8:32: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  int i, j, n, m, ans = 0; scanf("%d%d", &n, &m);
                           ~~~~~^~~~~~~~~~~~~~~~
garage.cpp:9:36: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  for (i = 1; i <= n; i++)H.push(-i), scanf("%d", &C[i]);
                          ~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~
garage.cpp:10:31: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  for (i = 1; i <= m; i++)scanf("%d", &V[i]);
                          ~~~~~^~~~~~~~~~~~~
garage.cpp:12:15: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   int x; scanf("%d", &x);
          ~~~~~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 252 KB Output is correct
2 Correct 2 ms 356 KB Output is correct
3 Correct 2 ms 500 KB Output is correct
4 Correct 2 ms 500 KB Output is correct
5 Correct 2 ms 500 KB Output is correct
6 Correct 2 ms 500 KB Output is correct
7 Correct 3 ms 500 KB Output is correct
8 Correct 3 ms 500 KB Output is correct
9 Correct 2 ms 500 KB Output is correct
10 Correct 2 ms 540 KB Output is correct
11 Correct 2 ms 592 KB Output is correct
12 Correct 2 ms 592 KB Output is correct
13 Correct 2 ms 592 KB Output is correct
14 Correct 2 ms 592 KB Output is correct
15 Correct 4 ms 592 KB Output is correct
16 Correct 3 ms 596 KB Output is correct
17 Correct 3 ms 620 KB Output is correct
18 Correct 2 ms 620 KB Output is correct
19 Correct 3 ms 620 KB Output is correct
20 Correct 3 ms 620 KB Output is correct