이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
//Be Name Khoda
#include<bits/stdc++.h>
#pragma GCC optmize("Ofast,unroll-loops")
#pragma GCC target ("avx2,tune=native")
using namespace std;
#define ll long long
#define ld long double
#define all(x) x.begin(), x.end()
#define pii pair<int, int>
#define pll pair<ll, ll>
#define plll pair<pll, ll>
const int mxn = 316;
ll n, m, k, q, w;
int mx[mxn * mxn];
vector<ll> a, b, g, f, A;
vector<pll> v;
bitset<mxn * mxn> dp, pd;
void input() {
cin >> n >> m >> k;
for(int i = 0; i < n; i++) {
cin >> q;
a.push_back(q);
w += q;
}
for(int i = 0; i < m; i++) {
cin >> q;
b.push_back(q);
if(q <= n) {
g.push_back(q);
} else {
f.push_back(q);
}
}
}
void solve() {
if(m < k) {
cout << "Impossible\n";
return;
}
for(auto u : a) {
if(u < k) {
cout << "Impossible\n";
return;
}
}
dp.set(0);
for(auto u : g) {
dp |= (dp << u);
}
pd.set(0);
for(auto u : f) {
for(int i = mxn * mxn - 1; i > u - 1; i--) {
if(pd[i - u]) {
pd.set(i);
mx[i] = max(mx[i - u] + 1, mx[i]);
}
}
}
for(int i = 0; i < mxn * mxn; i++) {
if(pd[i]) {
v.push_back({mx[i], i});
}
}
for(int i = 0; i < mxn * mxn; i = dp._Find_next(i)) {
A.push_back(i);
} A.push_back(mxn * mxn);
ll ans = mxn * mxn, sum = 0, ptr;
for(int i = 0; i < int(v.size()); i++) {
sum = w - v[i].second;
sum = max(sum, n * k - v[i].first * k);
if(sum < 0) sum = 0;
ptr = *lower_bound(all(A), sum);
if(ptr < mxn * mxn) {
sum = ptr + v[i].second;
if(sum - w > -1) {
ans = min(ans, sum - w);
}
}
}
if(ans == mxn * mxn) {
cout << "Impossible\n";
return;
}
cout << ans << endl;
}
int main() {
ios::sync_with_stdio(false); cin.tie(NULL);
input(), solve();
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
kitchen.cpp:4: warning: ignoring '#pragma GCC optmize' [-Wunknown-pragmas]
4 | #pragma GCC optmize("Ofast,unroll-loops")
|
# | 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... |