Submission #74890

# Submission time Handle Problem Language Result Execution time Memory
74890 2018-09-07T09:48:24 Z win11905 Garage (IOI09_garage) C++11
100 / 100
4 ms 880 KB
#include <cstdio>
#include <algorithm>
#include <vector>
#include <queue>
using namespace std;

const int MAXN = 1e2+5,MAXM = 1e4+5;
int N,M,cost[MAXN],weight[MAXM],cache[MAXN];
void read_input(){
	scanf("%d%d",&N,&M);
	for(int i = 1;i<=N;++i){
		scanf("%d",cost+i);
	}
	for(int i = 1;i<=M;++i){
		scanf("%d",weight+i);
	}
}
long long solve(){
	long long sum = 0;
	queue<int> Q;
	for(int i = 1;i<=2*M;++i){
		int now;
		scanf("%d",&now);
		if(now<0){
			now*=-1;
			for(int j = 1;j<=N;++j){
				if(cache[j]==now){
					cache[j] = 0;
					if(!Q.empty()){
						cache[j] = Q.front();
						sum+=weight[Q.front()]*cost[j];
						Q.pop();
					}
					break;
				}
			}
		}else{
			bool st = true;
			for(int j = 1;j<=N;++j){
				if(cache[j]==0){
					cache[j] = now;
					sum+=weight[now]*cost[j];
					st = false;
					break;
				}
			}
			if(st) Q.push(now);
		}
	}
	return sum;
}
int main(){
	//freopen("r","r",stdin);
	read_input();
	printf("%lld\n",solve());
}

Compilation message

garage.cpp: In function 'void read_input()':
garage.cpp:10: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:12:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d",cost+i);
   ~~~~~^~~~~~~~~~~~~
garage.cpp:15:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d",weight+i);
   ~~~~~^~~~~~~~~~~~~~~
garage.cpp: In function 'long long int solve()':
garage.cpp:23:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d",&now);
   ~~~~~^~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
3 Correct 2 ms 440 KB Output is correct
4 Correct 2 ms 440 KB Output is correct
5 Correct 2 ms 440 KB Output is correct
6 Correct 3 ms 460 KB Output is correct
7 Correct 2 ms 512 KB Output is correct
8 Correct 2 ms 652 KB Output is correct
9 Correct 2 ms 652 KB Output is correct
10 Correct 2 ms 652 KB Output is correct
11 Correct 2 ms 652 KB Output is correct
12 Correct 2 ms 652 KB Output is correct
13 Correct 2 ms 652 KB Output is correct
14 Correct 2 ms 652 KB Output is correct
15 Correct 2 ms 764 KB Output is correct
16 Correct 3 ms 764 KB Output is correct
17 Correct 3 ms 764 KB Output is correct
18 Correct 4 ms 764 KB Output is correct
19 Correct 3 ms 880 KB Output is correct
20 Correct 3 ms 880 KB Output is correct