답안 #124889

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
124889 2019-07-04T05:32:06 Z 박상수(#3055) Kitchen (BOI19_kitchen) C++14
51 / 100
163 ms 110128 KB
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <memory.h>
#include <math.h>
#include <assert.h>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <string>
#include <algorithm>
#include <iostream>
#include <functional>
#include <unordered_set>
#include <bitset>
#include <time.h>
#include <limits.h>

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define Fi first
#define Se second
#define pb push_back
#define szz(x) (int)x.size()
#define rep(i,n) for(int i=0;i<n;i++)
#define all(x) x.begin(),x.end()
typedef tuple<int, int, int> t3;

int N, M, K, A[310], B[310];
bitset <90090> X;
int dp[310][90090];

int main() {
    scanf("%d%d%d", &N, &M, &K);
    for(int i=1;i<=N;i++) scanf("%d", A + i);
    sort(A+1, A+1+N);
    int sa = 0; for(int i=1;i<=N;i++) sa += A[i];
    for(int i=1;i<=M;i++) scanf("%d", B + i);
    sort(B+1, B+1+M, greater<int>());
    auto NO = [&]() { puts("Impossible"); exit(0); };
    for(int i=1;i<=N;i++) if(A[i] < K) NO();
    int ans = 1e9;
    memset(dp, -1, sizeof dp);
    dp[0][0] = 0;
    int sb = 0;
    for(int i=1;i<=M;i++) if(B[i] >= K) ++sb;

    auto upd = [&](int &a, int b) { if(a < b) a = b; };
    for(int i=0;i<sb;i++) {
        for(int j=0;j<90090;j++) if(dp[i][j] != -1) {
            upd(dp[i+1][j], dp[i][j]);
            upd(dp[i+1][j+B[i+1]], dp[i][j] + 1);
        }
    }
    X[0] = 1;
    for(int i=M-1;i>=sb;i--) {
        X = (X | (X << B[i+1]));
    }
    int nx[90090] = {};
    nx[90089] = -1;
    for(int i=90088;i>=0;i--) {
        if(X[i]) nx[i] = i;
        else nx[i] = nx[i+1];
    }
    rep(a, 90090) if(dp[sb][a] != -1) {
        int b = dp[sb][a];
        int c = max({0, (K - b) * N, sa - a});
        if(nx[c] != -1) {
            ans = min(ans, a + nx[c]);
        }
    }

    if(ans > 1e8) NO();
    else printf("%d\n", ans - sa);
    return 0;
}

Compilation message

kitchen.cpp: In function 'int main()':
kitchen.cpp:37:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d%d%d", &N, &M, &K);
     ~~~~~^~~~~~~~~~~~~~~~~~~~~~
kitchen.cpp:38:32: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     for(int i=1;i<=N;i++) scanf("%d", A + i);
                           ~~~~~^~~~~~~~~~~~~
kitchen.cpp:41:32: 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);
                           ~~~~~^~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 92 ms 109944 KB Output is correct
2 Correct 92 ms 109944 KB Output is correct
3 Correct 92 ms 109944 KB Output is correct
4 Correct 92 ms 110072 KB Output is correct
5 Correct 92 ms 109944 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 91 ms 110004 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 92 ms 109944 KB Output is correct
2 Correct 92 ms 109944 KB Output is correct
3 Correct 92 ms 109944 KB Output is correct
4 Correct 92 ms 110072 KB Output is correct
5 Correct 92 ms 109944 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 91 ms 110004 KB Output is correct
9 Correct 93 ms 109984 KB Output is correct
10 Correct 93 ms 109972 KB Output is correct
11 Correct 93 ms 110072 KB Output is correct
12 Correct 93 ms 109916 KB Output is correct
13 Correct 93 ms 109944 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 128 ms 110072 KB Output is correct
2 Correct 131 ms 109940 KB Output is correct
3 Correct 151 ms 109932 KB Output is correct
4 Correct 163 ms 109972 KB Output is correct
5 Correct 147 ms 110072 KB Output is correct
6 Correct 124 ms 110128 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 108 ms 110008 KB Output is correct
2 Incorrect 94 ms 110044 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 92 ms 109944 KB Output is correct
2 Correct 92 ms 109944 KB Output is correct
3 Correct 92 ms 109944 KB Output is correct
4 Correct 92 ms 110072 KB Output is correct
5 Correct 92 ms 109944 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 91 ms 110004 KB Output is correct
9 Correct 93 ms 109984 KB Output is correct
10 Correct 93 ms 109972 KB Output is correct
11 Correct 93 ms 110072 KB Output is correct
12 Correct 93 ms 109916 KB Output is correct
13 Correct 93 ms 109944 KB Output is correct
14 Correct 128 ms 110072 KB Output is correct
15 Correct 131 ms 109940 KB Output is correct
16 Correct 151 ms 109932 KB Output is correct
17 Correct 163 ms 109972 KB Output is correct
18 Correct 147 ms 110072 KB Output is correct
19 Correct 124 ms 110128 KB Output is correct
20 Correct 108 ms 110008 KB Output is correct
21 Incorrect 94 ms 110044 KB Output isn't correct
22 Halted 0 ms 0 KB -