답안 #169393

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
169393 2019-12-20T07:36:03 Z Atalasion Kitchen (BOI19_kitchen) C++14
100 / 100
30 ms 764 KB
//khodaya khodet komak kon
#include <bits/stdc++.h>

#define F first
#define S second
#define pb push_back
#define all(x) x.begin(), x.end()
#pragma GCC optimise ("ofast")
#pragma GCC optimise("unroll-loops")

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;

const int N = 300 + 10;
const ll MOD = 1000000000 + 7;
const ll INF = 1000000000000000000;
const ll LOG = 25;

int n, m, k, a[N], b[N];
int dp[N * N];

int main(){
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	cin >> n >> m >> k;
	for (int i = 1; i <= n; i++) cin >> a[i];
	for (int i = 1; i <= m; i++) cin >> b[i];
	int sum = 0, sum1 = 0;
	sort(a + 1, a + n + 1);
	if (a[1] < k) return cout << "Impossible", 0;
	if (m < k) return cout << "Impossible", 0;
	for (int i = 1; i <= n; i++) sum += a[i];
	for (int i = 1; i <= m; i++) sum1 += b[i];
	if (sum1 < sum) return cout << "Impossible",0;
	//memset(dp, 31, sizeof dp);
	//dp[0] = 0;
	for (int i = 0; i < N * N; i++) dp[i] = -100000000;
	dp[0] = 0;
	for (int i = 1; i <= m; i++){
		for (int j = N * N - 1; j >= b[i]; j--){
			dp[j] = max(dp[j], dp[j - b[i]] + min(n, b[i]));
			//cout << j << ' ' << dp[j] << '\n';
		}
	}
	for (int i = sum; i < N * N; i++){
		if (dp[i] >= n * k) return cout << i - sum, 0;
	}
	cout << "Impossible", 0;







	return 0;
}

Compilation message

kitchen.cpp:8:0: warning: ignoring #pragma GCC optimise [-Wunknown-pragmas]
 #pragma GCC optimise ("ofast")
 
kitchen.cpp:9:0: warning: ignoring #pragma GCC optimise [-Wunknown-pragmas]
 #pragma GCC optimise("unroll-loops")
 
kitchen.cpp: In function 'int main()':
kitchen.cpp:50:25: warning: right operand of comma operator has no effect [-Wunused-value]
  cout << "Impossible", 0;
                         ^
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 764 KB Output is correct
2 Correct 2 ms 760 KB Output is correct
3 Correct 2 ms 732 KB Output is correct
4 Correct 2 ms 760 KB Output is correct
5 Correct 2 ms 760 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 764 KB Output is correct
2 Correct 2 ms 760 KB Output is correct
3 Correct 2 ms 732 KB Output is correct
4 Correct 2 ms 760 KB Output is correct
5 Correct 2 ms 760 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 4 ms 760 KB Output is correct
10 Correct 3 ms 632 KB Output is correct
11 Correct 4 ms 760 KB Output is correct
12 Correct 4 ms 760 KB Output is correct
13 Correct 4 ms 632 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 26 ms 760 KB Output is correct
2 Correct 23 ms 760 KB Output is correct
3 Correct 29 ms 760 KB Output is correct
4 Correct 30 ms 760 KB Output is correct
5 Correct 2 ms 380 KB Output is correct
6 Correct 21 ms 760 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 632 KB Output is correct
2 Correct 6 ms 760 KB Output is correct
3 Correct 6 ms 760 KB Output is correct
4 Correct 6 ms 632 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 764 KB Output is correct
2 Correct 2 ms 760 KB Output is correct
3 Correct 2 ms 732 KB Output is correct
4 Correct 2 ms 760 KB Output is correct
5 Correct 2 ms 760 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 4 ms 760 KB Output is correct
10 Correct 3 ms 632 KB Output is correct
11 Correct 4 ms 760 KB Output is correct
12 Correct 4 ms 760 KB Output is correct
13 Correct 4 ms 632 KB Output is correct
14 Correct 26 ms 760 KB Output is correct
15 Correct 23 ms 760 KB Output is correct
16 Correct 29 ms 760 KB Output is correct
17 Correct 30 ms 760 KB Output is correct
18 Correct 2 ms 380 KB Output is correct
19 Correct 21 ms 760 KB Output is correct
20 Correct 6 ms 632 KB Output is correct
21 Correct 6 ms 760 KB Output is correct
22 Correct 6 ms 760 KB Output is correct
23 Correct 6 ms 632 KB Output is correct
24 Correct 2 ms 376 KB Output is correct
25 Correct 21 ms 632 KB Output is correct
26 Correct 24 ms 632 KB Output is correct
27 Correct 17 ms 760 KB Output is correct
28 Correct 24 ms 632 KB Output is correct
29 Correct 25 ms 760 KB Output is correct
30 Correct 29 ms 760 KB Output is correct