답안 #949534

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
949534 2024-03-19T10:22:38 Z Darren0724 Kitchen (BOI19_kitchen) C++17
72 / 100
125 ms 262144 KB
#include <bits/stdc++.h>
using namespace std;
#define LCBorz ios_base::sync_with_stdio(false); cin.tie(0);
#define int long long
#define all(x) x.begin(), x.end()
#define endl '\n'
#define no cout<<"Impossible"<<endl;return 0;
const int N=200005;
const int INF=1e18;

int32_t main() {
    LCBorz;
    int n,m,k;cin>>n>>m>>k;
    if(m<k){
        no;
    }
    vector<int> a(n),b(m);
    int total=0,ta=0,tb=0;
    for(int i=0;i<n;i++){
        cin>>a[i];
        if(a[i]<k){
            no;
        }
        total+=a[i];
    }
    for(int i=0;i<m;i++){
        cin>>b[i];
        ta+=b[i];
    }
    tb=(k==1?1:k*n);
    vector dp(ta+1,vector(tb+1,0));
    dp[0][0]=1;
    for(int i=0;i<m;i++){
        for(int j=ta;j>=b[i];j--){
            int tmp=min(b[i],n);
            for(int j1=tb;j1>=0;j1--){
                dp[j][min(j1+tmp,tb)]|=dp[j-b[i]][j1];
            }
        }
    }
    int ans=-1;
    for(int i=total;i<=ta;i++){
        for(int j=(k==1?1:k*n);ans==-1&&j<=tb;j++){
            if(dp[i][j]){
                ans=i;break;
            }
        }
    }
    if(ans==-1){
        no;
    }
    else{
        cout<<ans-total<<endl;
    }

    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 5 ms 1372 KB Output is correct
10 Correct 2 ms 860 KB Output is correct
11 Correct 2 ms 604 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 125 ms 32604 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 41 ms 3928 KB Output is correct
2 Correct 43 ms 3420 KB Output is correct
3 Correct 44 ms 2908 KB Output is correct
4 Correct 59 ms 5460 KB Output is correct
5 Correct 61 ms 4952 KB Output is correct
6 Correct 30 ms 3164 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 32 ms 4444 KB Output is correct
2 Correct 18 ms 2652 KB Output is correct
3 Correct 26 ms 3676 KB Output is correct
4 Correct 67 ms 9052 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 5 ms 1372 KB Output is correct
10 Correct 2 ms 860 KB Output is correct
11 Correct 2 ms 604 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 125 ms 32604 KB Output is correct
14 Correct 41 ms 3928 KB Output is correct
15 Correct 43 ms 3420 KB Output is correct
16 Correct 44 ms 2908 KB Output is correct
17 Correct 59 ms 5460 KB Output is correct
18 Correct 61 ms 4952 KB Output is correct
19 Correct 30 ms 3164 KB Output is correct
20 Correct 32 ms 4444 KB Output is correct
21 Correct 18 ms 2652 KB Output is correct
22 Correct 26 ms 3676 KB Output is correct
23 Correct 67 ms 9052 KB Output is correct
24 Correct 0 ms 344 KB Output is correct
25 Runtime error 95 ms 262144 KB Execution killed with signal 9
26 Halted 0 ms 0 KB -