답안 #938703

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
938703 2024-03-05T12:52:22 Z vjudge1 Kitchen (BOI19_kitchen) C++17
29 / 100
68 ms 3416 KB
#include <bits/stdc++.h>
#define int long long
using namespace std;

signed main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n,m,k;
    cin >> n >> m >> k;
    vector<int> a(n),b(m);
    for (int i = 0; i < n; i++)
        cin >> a[i];
    for (int i = 0; i < m; i++)
        cin >> b[i];
    if (k > m)
        {
        cout << "Impossible\n";
        return 0;
        }
    if (k == 1)
    {
    int sum = 0LL;
    for (int i = 0; i < m; i++)
        sum+=b[i];
    vector<vector<bool>> dp(m,vector<bool>(sum+1));
    dp[0][0] = 1;
    dp[0][b[0]] = 1;
    for (int i = 1; i < m; i++)
        for (int j = 0; j <= sum; j++)
        {
            if (j-b[i] >= 0)
                dp[i][j] = (dp[i-1][j-b[i]] | dp[i-1][j]);
            else
                dp[i][j] = dp[i-1][j];
        }
    /*for (int i = 0; i <= sum ;i++)
    {
        cout << "can " << i << ' ' << dp[m-1][i] << '\n';
    }*/
    int oth = 0;
    for (int i = 0; i < n; i++)
        oth+=a[i];
        
    for (int i = oth; i <= sum; i++)
        if (dp[m-1][i])
        {
            cout << i-oth << '\n';
            return 0;
        }
    cout << "Impossible\n";
    }
    else
    {
        
         int oth = 0;
        if (m==2)
        {
        for (int i = 0; i < n; i++)
            oth+=a[i];
        int fr = b[0], sr = b[1];
        if (fr > sr)
            swap(fr,sr);
        for (int i = 0; i < n; i++)
        {
            if (a[i] == 1)
            {
                cout << "Impossible\n";
                return 0;
            }
            if (sr - a[i] < n-i-1)
            {
                a[i] -= (sr-n+i+1);
                sr = n-i-1;
            }
            else
            {
                sr-=a[i]-1;
                a[i] = 1;
                
            }
            
            
                if (fr - a[i] < n-i-1)
                {
                    a[i] -= fr-n+i+1;
                    fr = n-i-1;
                }
                else
                {
                    fr-=a[i];
                    a[i] = 0;
                }
           
                
            if (a[i] != 0)
            {
                cout << "Impossible\n";
                return 0;
            }
        }
       
        cout << b[0] + b[1] - oth << '\n';
        }
        else
        {
            if (b[0] >= oth)
            {
                cout << oth-b[0] << '\n';
            }
            else
            {
                cout << "Impossible\n";
                return 0;
            }
        }
    }
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 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 1 ms 344 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 Incorrect 0 ms 348 KB Output isn't correct
10 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 48 ms 2396 KB Output is correct
2 Correct 36 ms 1884 KB Output is correct
3 Correct 40 ms 2136 KB Output is correct
4 Correct 68 ms 3416 KB Output is correct
5 Correct 68 ms 3416 KB Output is correct
6 Correct 29 ms 1624 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 344 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 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 Incorrect 0 ms 348 KB Output isn't correct
10 Halted 0 ms 0 KB -