답안 #545589

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
545589 2022-04-04T23:21:58 Z pere_gil Garage (IOI09_garage) C++17
100 / 100
1 ms 340 KB
#include "bits/stdc++.h"
using namespace std;

int main(){
	int n,m; scanf("%d %d",&n,&m);
	vector<int> r(n+1);
	for(int i=1;i<=n;i++) scanf("%d",&r[i]);
	vector<int> h(m+1);
	for(int i=1;i<=m;i++) scanf("%d",&h[i]);

	queue<int> car;
	priority_queue<int,vector<int>,greater<int>> parking;
	for(int i=n;i>0;i--) parking.push(i);
	vector<int> v(m+1);
	m*=2;
	long long res=0;
	while(m--){
		int act; scanf("%d",&act);
		if(act>0){
			if(parking.empty()) car.push(act);
			else{
				v[act]=parking.top();
				parking.pop();
				res+=h[act]*r[v[act]];
			}
		}
		else{
			parking.push(v[-act]);
			if(!car.empty()){
				act=car.front(); car.pop();
				v[act]=parking.top();
				parking.pop();
				res+=h[act]*r[v[act]];
			}
		}
	}
	printf("%lld\n",res);
	
	return 0;
}

Compilation message

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