답안 #602109

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
602109 2022-07-22T14:58:25 Z nguyentu Kitchen (BOI19_kitchen) C++14
0 / 100
578 ms 11764 KB
#include <bits/stdc++.h>

#pragma GCC target("avx2")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")

using namespace std;

#define ii pair<int , int>  
#define iv pair<ii , ii>
#define iii pair<int , ii>
#define fi first
#define se second
#define int long long
const int inf = 1e18 + 7;
const int MAX_N = 41;
const int MOD = 1e9 + 7;

int n , m , K;
int f[41][41][1600];
int a[MAX_N];
int b[MAX_N];
signed main() {
    ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL);
    cin >> n >> m >> K;
    int W = 0 , w = 0;
    for (int i = 1 ; i <= n ; i++) {
        cin >> a[i];
        if (a[i] < K) {
            cout << "Impossible";
            return 0;
        }
        W += a[i];
    }
    for (int i = 1 ; i <= m ; i++) {
        cin >> b[i];
        w += b[i];
    }
    if (W > w || K > m) {
        cout << "Impossible";
        return 0;
    }
    for (int i = 1 ; i <= m ; i++) {
        f[i - 1][0][0] = 1;
        for (int j = 1 ; j <= m ; j++) {
            for (int k = b[i] ; k <= w ; k++) {
                if (f[i - 1][j - 1][k - b[i]]) {
                    f[i][j][k] = 1;
                }
            }
        }
        for (int j = 1 ; j <= m ; j++) {
            for (int k = 1 ; k <= w ; k++) {
                if (f[i - 1][j][k]) {
                    f[i][j][k] = 1;
                }
            }
        }
    }
    int ans = inf; 
    for (int i = K ; i <= max(K , m); i++) {
        for (int j = W ; j <= w ; j++) {
            if (f[m][i][j]) 
                ans = min(ans , j - W);
        }
    }
    cout << ans;
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 0 ms 328 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Incorrect 1 ms 332 KB Output isn't correct
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 0 ms 328 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Incorrect 1 ms 332 KB Output isn't correct
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 578 ms 11764 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 6 ms 4436 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 0 ms 328 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Incorrect 1 ms 332 KB Output isn't correct
6 Halted 0 ms 0 KB -