Submission #124913

# Submission time Handle Problem Language Result Execution time Memory
124913 2019-07-04T06:36:25 Z 이온조(#3049) Kitchen (BOI19_kitchen) C++14
52 / 100
1000 ms 4476 KB
#include <bits/stdc++.h>
using namespace std;
using pii = pair<int, int>;

map<pii, int> D;
int A[333], B[333];

void FAIL() {
	puts("Impossible");
	exit(0);
}

int main() {
	int N, M, K; scanf("%d%d%d",&N,&M,&K);
	int AS = N*K, BS = 0;
	for(int i=1; i<=N; i++) {
		scanf("%d",&A[i]);
		if(A[i] < K) FAIL();
		BS += A[i] - K;
	}
	for(int i=1; i<=M; i++) scanf("%d",&B[i]);
	D[{0, 0}] = 0;
	for(int i=1; i<=M; i++) {
		vector<pair<pii, int> > UPD;
		for(auto& it: D) {
			pii DS; int DV; tie(DS, DV) = it;
			int AD = min({AS - DS.first, N, B[i]});
			int NA = DS.first + AD, NB = min(DS.second + B[i] - AD, BS);
			UPD.push_back({{NA, NB}, DV + max(0, DS.second + B[i] - AD - BS)});
			// printf("i: %d, DS: {%d, %d}, DV: %d, updating th: {%d, %d}, value: %d\n", i, DS.first, DS.second, DV, NA, NB, DV + max(0, DS.second + B[i] - AD - BS));
		}
		for(auto& it: UPD) {
			if(D.find(it.first) == D.end()) D[it.first] = 1e9;
			auto &th = D[it.first];
			th = min(th, it.second);
		}
	}
	if(D.find({AS, BS}) == D.end()) FAIL();
	else printf("%d", D[{AS, BS}]);
	return 0;
}

Compilation message

kitchen.cpp: In function 'int main()':
kitchen.cpp:14:20: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  int N, M, K; scanf("%d%d%d",&N,&M,&K);
               ~~~~~^~~~~~~~~~~~~~~~~~~
kitchen.cpp:17:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d",&A[i]);
   ~~~~~^~~~~~~~~~~~
kitchen.cpp:21:31: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  for(int i=1; i<=M; i++) scanf("%d",&B[i]);
                          ~~~~~^~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 2 ms 256 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 3 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 256 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 2 ms 256 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 3 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 256 KB Output is correct
9 Correct 4 ms 504 KB Output is correct
10 Correct 3 ms 364 KB Output is correct
11 Correct 3 ms 376 KB Output is correct
12 Correct 3 ms 376 KB Output is correct
13 Correct 4 ms 504 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 495 ms 2808 KB Output is correct
2 Correct 329 ms 2892 KB Output is correct
3 Execution timed out 1063 ms 4476 KB Time limit exceeded
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 9 ms 760 KB Output is correct
2 Correct 53 ms 2108 KB Output is correct
3 Correct 5 ms 376 KB Output is correct
4 Correct 5 ms 504 KB Output is correct
5 Correct 2 ms 256 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 2 ms 256 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 3 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 256 KB Output is correct
9 Correct 4 ms 504 KB Output is correct
10 Correct 3 ms 364 KB Output is correct
11 Correct 3 ms 376 KB Output is correct
12 Correct 3 ms 376 KB Output is correct
13 Correct 4 ms 504 KB Output is correct
14 Correct 495 ms 2808 KB Output is correct
15 Correct 329 ms 2892 KB Output is correct
16 Execution timed out 1063 ms 4476 KB Time limit exceeded
17 Halted 0 ms 0 KB -