답안 #74655

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
74655 2018-09-05T15:42:38 Z arman_ferdous Garage (IOI09_garage) C++17
100 / 100
4 ms 888 KB
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
int n, m, r[110], w[2010], arr[110];

int main() {
	scanf("%d %d", &n, &m);
	for(int i = 1; i <= n; i++)
		scanf("%d", &r[i]);
	for(int i = 1; i <= m; i++)
		scanf("%d", &w[i]);
	ll ans = 0;
	int Q = m + m;
	queue<int> q;
	while(Q--) {
		int id; scanf("%d", &id);
		if(id < 0) { 
			id = -id;
			for(int i = 1; i <= n; i++) if(arr[i] == id) {
				arr[i] = 0;
				if(!q.empty()) {
					arr[i] = q.front();
					ans += 1ll * w[arr[i]] * r[i];
					q.pop();
				} break;
			}
		}
		else {
			for(int i = 1; i <= n; i++) if(arr[i] == 0) {
				arr[i] = id; id = 0; 
				ans += 1ll * w[arr[i]] * r[i]; break;
			}
			if(id) q.push(id);
		}
	} printf("%lld\n", ans);
	return 0;
}

Compilation message

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