Submission #925852

# Submission time Handle Problem Language Result Execution time Memory
925852 2024-02-12T10:04:52 Z vjudge1 Kitchen (BOI19_kitchen) C++17
9 / 100
1000 ms 452 KB
//Bismillahir-Rahmanir-Rahim

#include <bits/stdc++.h>
//#pragma comment(linker, "/stack:200000000")
//#pragma GCC optimize("O1,O2,O3,Ofast,unroll-loops")
//#pragma GCC target("sse,sse2,sse3,sse4,sse4.1,sse4.2,popcnt,avx,avx2")

#define pb push_back
#define pii pair <int, int>
#define pll pair <long long, long long>
#define pld pair <long double, long double>
#define ll long long
#define ld long double
#define x first
#define y second
#define all(v) v.begin(),v.end()
#define sz(s) (int)s.size()
#define skip continue
#define bpop(x) (ll)__builtin_popcountll(x)

using namespace std;

const int N = 3e2 + 7;
const int M = 1e3 + 7;
const int maxA = 2e6 + 7;
const int inf = 1e9 + 7;
const ll INF = 2e18 + 7;
const int MOD = 1e9 + 7;
const ld eps = 1e-9;

pii dir[] = {{0, 1}, {1, 0}, {0, -1}, {-1, 0}};

//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

//#define int long long

int n, m, k, a[N], b[N], init[N];
void solve() {
    cin >> n >> m >> k;
    int total = 0;
    for (int i = 0;i < n;i++) {
        cin >> a[i];
        if (a[i] < k)cout << "Impossible", exit(0);
        total -= a[i];
    }
    for (int i = 0;i < m;i++)cin >> b[i], total += b[i], init[i] = b[i];
    if (total < 0)cout << "Impossible", exit(0);
    total = 0;
    for (int i = 0;i < n;i++)total += a[i];
    sort(a + 1, a + n + 1), sort(b + 1, b + m + 1);
    int ans = inf;
    for (int mask = 0;mask < (1ll << m);mask++) {
        if (bpop(mask) < k)skip;
        for (int i = 0;i < m;i++)b[i] = init[i];
        vector <int> pre(n + 1, 0);
        int pos = 0, sum = 0;
        //cout << mask << ":\n";
        for (int cook = m - 1;cook >= 0;cook--) {
            if ((mask >> cook) & 1) {
                sum += b[cook];
                int r = min(n, pos + b[cook]);
                int l = pos;
                pre[pos]++, pre[r]--, b[cook] -= r - pos, pos = r % n;
                if (pos == 0) {
                    pre[pos]++;
                    r = min(l, pos + b[cook]);
                    pre[r]--;
                }
            }
        }
        bool ok = 1;
        for (int i = 1;i < n;i++)pre[i] += pre[i - 1], ok &= (pre[i] >= k);
        //for (int i = 0;i < n;i++)cout << pre[i] << ' ';
        //cout << '\n';
        if (sum >= total && ok)ans = min(ans, sum - total);
    }
    if (ans == inf)cout << "Impossible";
    else cout << ans;
}
signed main() {
    //srand(time(NULL));
    ios_base::sync_with_stdio(0);
    cout.tie(0);
    //freopen("tests.in", "r", stdin);
    //freopen("milkorder.out", "w", stdout);
    int test = 1;
    //cin >> test;
    for (int t = 1;t <= test;t++) {
        //cout << "Case " << t << ": ";
        solve();
    }
    return 0;
}

# Verdict Execution time Memory 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
# Verdict Execution time Memory 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 1 ms 348 KB Output is correct
10 Correct 2 ms 452 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 4 ms 348 KB Output is correct
13 Incorrect 19 ms 348 KB Output isn't correct
14 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 344 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1054 ms 348 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory 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 1 ms 348 KB Output is correct
10 Correct 2 ms 452 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 4 ms 348 KB Output is correct
13 Incorrect 19 ms 348 KB Output isn't correct
14 Halted 0 ms 0 KB -