# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
365778 |
2021-02-12T10:42:53 Z |
Yomapeed |
Kitchen (BOI19_kitchen) |
C++17 |
|
1000 ms |
59372 KB |
#include<bits/stdc++.h>
#define pi 3.141592653589793238
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#define MOD 1000000007
#define INF 999999999999999999
#define pb push_back
#define ff first
#define ss second
#define mt make_tuple
#define ll long long
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
typedef tree<ll, null_type, less_equal<ll>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
const int N = 50 + 2;
bool dp[N][N][N][N * N];
void chmin(ll& a, ll b){
a = min(a, b);
}
void eq(bool& a, bool b){
a = b;
}
int main() {
//freopen("input.txt", "r", stdin);
//freopen("output.txt", "w", stdout);
fast;
ll T = 1, i, j;
//cin >> T;
while (T--) {
ll n, m, k;
cin >> n >> m >> k;
vector<ll> a(n), b(m);
bool flag = true;
ll sum = 0;
ll sa = 0;
for(i = 0; i < n; i++){
cin >> a[i];
if(a[i] < k){
flag = false;
}
sum += a[i];
}
sa = sum;
for(i = 0; i < m; i++){
cin >> b[i];
sum -= b[i];
}
if(sum > 0){
flag = false;
}
if(m < k){
flag = false;
}
if(!flag){
cout << "Impossible\n";
return 0;
}
dp[0][0][0][0] = 1;
for(i = 0; i < m; i++){
ll B = min(b[i], n);
for(ll x = 0; x < n; x++){
for(ll done = 0; done <= 40; done++){
for(ll s = 0; s < 1700; s++){
if(dp[i][x][done][s] == 0){
continue;
}
dp[i + 1][x][done][s] += dp[i][x][done][s];
if(x + B < n){
eq(dp[i + 1][x + B][done][s + b[i]], dp[i][x][done][s]);
dp[i + 1][x + B][done][s + b[i]] += dp[i][x + B][done][s + b[i]];
//cout << dp[i + 1][x + B][done][s + b[i]] << " " << i + 1 << " " << x + B << " " << done << endl;
//cout << s + b[i] << endl;
}
else{
eq(dp[i + 1][x + B - n][done + 1][s + b[i]], dp[i][x][done][s]);
dp[i + 1][x + B - n][done+ 1][s + b[i]] += dp[i][x + B - n][done + 1][s + b[i]];
////cout << dp[i + 1][x + B - n][done + 1][s + b[i]] << " " << i + 1 << " " << x + B - n << " " << done + 1 << endl;
////cout << s + b[i] << endl;
}
}
}
}
}
// if(dp[m][0][k] == INF){
// cout << "Impossible\n";
// return 0;
// }
//cout << sa << endl;
ll ans = INF;
for(i = 0; i < n; i++){
for(j = sa; j < 1700; j++){
for(ll kk = k; kk <= 40; kk++){
if(dp[m][i][kk][j]){
chmin(ans, j - sa);
}
}
}
}
if(ans >= 10000000){
cout << "Impossible\n";
return 0;
}
cout << ans << endl;
}
return 0;
}
Compilation message
kitchen.cpp:4: warning: ignoring #pragma GCC optimization [-Wunknown-pragmas]
4 | #pragma GCC optimization ("O3")
|
kitchen.cpp:5: warning: ignoring #pragma GCC optimization [-Wunknown-pragmas]
5 | #pragma GCC optimization ("unroll-loops")
|
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
364 KB |
Output is correct |
2 |
Correct |
2 ms |
364 KB |
Output is correct |
3 |
Correct |
2 ms |
364 KB |
Output is correct |
4 |
Correct |
5 ms |
364 KB |
Output is correct |
5 |
Incorrect |
70 ms |
1260 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
364 KB |
Output is correct |
2 |
Correct |
2 ms |
364 KB |
Output is correct |
3 |
Correct |
2 ms |
364 KB |
Output is correct |
4 |
Correct |
5 ms |
364 KB |
Output is correct |
5 |
Incorrect |
70 ms |
1260 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1086 ms |
39516 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
101 ms |
13036 KB |
Output is correct |
2 |
Correct |
107 ms |
38300 KB |
Output is correct |
3 |
Correct |
153 ms |
59372 KB |
Output is correct |
4 |
Correct |
168 ms |
55660 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
364 KB |
Output is correct |
2 |
Correct |
2 ms |
364 KB |
Output is correct |
3 |
Correct |
2 ms |
364 KB |
Output is correct |
4 |
Correct |
5 ms |
364 KB |
Output is correct |
5 |
Incorrect |
70 ms |
1260 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |