답안 #938758

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
938758 2024-03-05T13:51:22 Z vjudge1 Kitchen (BOI19_kitchen) C++17
51 / 100
68 ms 3420 KB
#include <bits/stdc++.h>
#include <random>
#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];
        if (k > a[i])
        {
            cout << "Impossible\n";
            return 0;
        }
    }
    for (int i = 0; i < m; i++)
        cin >> b[i];
    sort(b.begin(),b.end());
    int oth = 0;
    for (int i = 0; i < n; i++)
        oth+=a[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 = oth; i <= sum; i++)
        if (dp[m-1][i])
        {
            cout << i-oth << '\n';
            return 0;
        }
    cout << "Impossible\n";
    }
    else
    {
        if(m > 15)
        {
            cout << "DARJAN JUGOVIC I LOVE YOU\n";
            return 0;
        }
        int cost = 1e9;
        for (int mask = 1; mask < (1<<(m+1)); mask++)
        {
            vector<int> arr;
            for (int i = 0; i < m; i++)
                if (mask&(1<<i))
                    arr.push_back(b[i]);
            if (k > arr.size())
                continue;
            int g = arr.size();
            int sum = 0;
            int minus = 0;
            for (int i = 0; i < g; i++)
                sum+=arr[i];
            if (oth > sum)
                continue;
            
            for (int i = 0; i < g-k+1; i++)
            {
                minus+=arr[i];
                if (minus >= n)
                {
                    cost = min(cost,sum-oth);
                    break;
                }
                int oduz = arr[i];
                for (int j = i; j < i+k; j++)
                {
                    arr[i]-=oduz;
                }
            }
        }
        if (cost == 1e9)
        {
            cout << "Impossible\n";
            return 0;
        }
        else
            cout << cost << '\n';
        
    }
    return 0;
}

Compilation message

kitchen.cpp: In function 'int main()':
kitchen.cpp:76:19: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   76 |             if (k > arr.size())
      |                 ~~^~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 344 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 344 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 10 ms 348 KB Output is correct
10 Correct 10 ms 348 KB Output is correct
11 Correct 10 ms 348 KB Output is correct
12 Correct 10 ms 348 KB Output is correct
13 Correct 10 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 47 ms 2396 KB Output is correct
2 Correct 35 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 3420 KB Output is correct
6 Correct 29 ms 1628 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 344 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 10 ms 348 KB Output is correct
10 Correct 10 ms 348 KB Output is correct
11 Correct 10 ms 348 KB Output is correct
12 Correct 10 ms 348 KB Output is correct
13 Correct 10 ms 348 KB Output is correct
14 Correct 47 ms 2396 KB Output is correct
15 Correct 35 ms 1884 KB Output is correct
16 Correct 40 ms 2136 KB Output is correct
17 Correct 68 ms 3416 KB Output is correct
18 Correct 68 ms 3420 KB Output is correct
19 Correct 29 ms 1628 KB Output is correct
20 Incorrect 0 ms 348 KB Output isn't correct
21 Halted 0 ms 0 KB -