답안 #900404

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
900404 2024-01-08T08:49:15 Z n3rm1n Kitchen (BOI19_kitchen) C++17
29 / 100
1000 ms 1116 KB
#include<bits/stdc++.h>
#define endl '\n'
using namespace std;
const long long MAXN = 305;
void speed()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
}
long long n, m, k;
long long a[MAXN], b[MAXN];
long long total = 0;
void read()
{
    cin >> n >> m >> k;
    for (long long i = 1; i <= n; ++ i)
    {
        cin >> a[i];
        total += a[i];
    }
    for (long long i = 1; i <= m; ++ i)
        cin >> b[i];

    for (long long i = 1; i <= n; ++ i)
    {
        if(a[i] < k)
        {
            cout << "Impossible" << endl;
            exit(0);
        }
    }

}
long long taken[MAXN];
long long p[MAXN], notused[MAXN];
long long solve()
{
    memset(taken, 0, sizeof(taken));
    memset(notused, 0, sizeof(notused));
    long long left = total, sumup = 0;
    long long ok = 0;

    for (long long i = 1; i <= m; ++ i)
    {
        if(p[i])
        {
            notused[i] = b[i];
            for (long long j = 1; j <= n; ++ j)
            {
                if(taken[j] < k && notused[i] > 0)
                {
                    taken[j] ++;
                    if(taken[j] == k)ok ++;
                    notused[i] --;
                    left --;
                }
            }
            sumup += notused[i];
        }
    }
    if(sumup < left || ok < n)return 1e13;
    else
    {

        return sumup - left;
    }
}
long long ans = 1e13;
void gen(long long pos)
{
    if(pos > m)
    {
        ans = min(ans, solve());
        return;
    }
    p[pos] = 0;
    gen(pos+1);
    p[pos] = 1;
    gen(pos+1);
}
long long dp[MAXN * MAXN + MAXN * MAXN];
void solve_k1()
{
    dp[0] = 1;
    for (long long i = 1; i <= m; ++ i)
    {
        for (long long j = total; j >= 0; -- j)
            if(dp[j])dp[j+b[i]] = 1;
    }
    for (long long i = total; i <= 2*total; ++ i)
    {
        if(dp[i])
        {
            cout << i - total << endl;
            exit(0);
        }
    }
    cout << "Impossible" << endl;
}
int main()
{
    speed();
    read();
    if(k == 1)
    {
        solve_k1();
        return 0;
    }
    gen(1);
    if(ans == 1e13)cout << "Impossible" << endl;
    else cout << ans << endl;
    return 0;
}
/**
8 15 10
162 161 155 165 238 182 177 244
184 135 225 297 269 220 226 118 292 281 179 137 100 142 287


*/
# 결과 실행 시간 메모리 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 8 ms 348 KB Output is correct
10 Correct 6 ms 348 KB Output is correct
11 Correct 9 ms 348 KB Output is correct
12 Correct 15 ms 472 KB Output is correct
13 Incorrect 98 ms 348 KB Output isn't correct
14 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 856 KB Output is correct
2 Correct 9 ms 860 KB Output is correct
3 Correct 9 ms 604 KB Output is correct
4 Correct 16 ms 944 KB Output is correct
5 Correct 17 ms 1116 KB Output is correct
6 Correct 8 ms 604 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1075 ms 348 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 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 8 ms 348 KB Output is correct
10 Correct 6 ms 348 KB Output is correct
11 Correct 9 ms 348 KB Output is correct
12 Correct 15 ms 472 KB Output is correct
13 Incorrect 98 ms 348 KB Output isn't correct
14 Halted 0 ms 0 KB -