답안 #899586

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
899586 2024-01-06T13:49:05 Z josanneo22 Garage (IOI09_garage) C++17
100 / 100
1 ms 604 KB
#include<bits/stdc++.h>
using namespace std;
using i64 = long long;

#define L(i,j,k) for(int i=j;i<=k;i++)
#define R(i,j,k) for(int i=j;i>=k;i--)

constexpr int _N = 1E4 + 500;
int N, M, R[_N], W[_N], pos[_N];
queue<int> q;

int main() {
	scanf("%d%d", &N,&M);
	L(i,1,N) scanf("%d", &R[i]);
	L(i,1,M) scanf("%d", &W[i]);
	set<int> S;
	L(i,1,N) S.insert(i);
	int ans=0;
	L(i,1,2*M){
		int x; scanf("%d",&x);
		if(x<0){
			x=abs(x);
			if(q.empty()){
				S.insert(pos[x]);
			}
			else{
				int f=q.front(); q.pop();
				pos[f]=pos[x];
				ans+=W[f]*R[pos[f]];
			}
		}
		else{
			if(S.empty()){
				q.push(x);
			}
			else{
				int where=*S.begin();
				pos[x]=where;
				ans+=W[x]*R[where];
				S.erase(S.begin());
			}
		}
	}
	printf("%d", ans);
}

Compilation message

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