답안 #348796

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
348796 2021-01-15T18:19:11 Z Mefarnis Garage (IOI09_garage) C++14
100 / 100
1 ms 384 KB
#include <bits/stdc++.h>
#define maxn 101
#define maxm 2001
using namespace std;

int n,m,ans;
int r[maxn];
int w[maxm];
int slot[maxm];
bool mark[maxn];
queue<int> Q;

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]);
	for( int q = 0 , id ; q < 2*m ; q++ ) {
		scanf("%d",&id);
		if(id > 0) {
			int idx = -1;
			for( int i = 1 ; i <= n ; i++ )
				if(!mark[i]) {
					idx = i;
					slot[id] = i;
					mark[i] = true;
					ans += r[i] * w[id];
					break;
				}
			if(idx == -1)
				Q.push(id);
		}
		else {
			id = -id;
			if(Q.empty())
				mark[slot[id]] = false;
			else {
				int car = Q.front();
				Q.pop();
				ans += r[slot[id]] * w[car];
				slot[car] = slot[id];
			}
		}
	}
	printf("%d\n",ans);
	return 0;
}

Compilation message

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