이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx")
#include <bits/stdc++.h>
#define Loop(x,l,r) for (ll x = (l); x < (ll)(r); ++x)
#define LoopR(x,l,r) for (ll x = (r)-1; x >= (ll)(l); --x)
typedef long long ll;
typedef std::pair<int, int> pii;
typedef std::pair<ll , ll > pll;
using namespace std;
const int N = 320;
int meal_cnt, chef_cnt, k;
int chef_time[N], meal_sum_time;
bitset<N*N> less_bs;
int nxt_less[N*N];
bitset<N*N> more_bs[N];
vector<int> less_chef;
vector<int> more_chef;
int main()
{
cin.tie(0) -> sync_with_stdio(false);
cin >> meal_cnt >> chef_cnt >> k;
Loop (i,0,meal_cnt) {
int x;
cin >> x;
if (x < k) {
cout << "Impossible\n";
return 0;
}
meal_sum_time += x;
}
Loop (i,0,chef_cnt) {
int x;
cin >> x;
(x <= meal_cnt? less_chef: more_chef).push_back(x);
}
less_bs[0] = 1;
for (int x : less_chef)
less_bs |= less_bs << x;
nxt_less[N*N-1] = N*N;
LoopR (i,0,N*N-1)
nxt_less[i] = less_bs[i]? i: nxt_less[i+1];
more_bs[0][0] = 1;
for (int x : more_chef) {
LoopR (i,1,N)
more_bs[i] |= more_bs[i-1] << x;
}
int ans = N*N;
Loop (cnt_more,0,N) Loop (time_more,0,N*N) {
if (!more_bs[cnt_more][time_more])
continue;
int req = 0;
req = max(req, meal_sum_time - (int)time_more);
req = max(req, (int)(k-cnt_more)*meal_cnt);
if (req >= N*N || nxt_less[req] == N*N)
continue;
ans = min(ans, nxt_less[req] + (int)time_more - meal_sum_time);
}
if (ans == N*N)
cout << "Impossible\n";
else
cout << ans << '\n';
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |