Submission #661037

#TimeUsernameProblemLanguageResultExecution timeMemory
661037GusterGoose27Uplifting Excursion (BOI22_vault)C++11
5 / 100
5073 ms2300 KiB
#pragma GCC optimize("Ofast") #pragma GCC target("avx2") #include <bits/stdc++.h> using namespace std; typedef pair<int, int> pii; typedef long long ll; const int MAXN = 100; const int MXVAL = 505000; int n; ll target; int cnt[2*MAXN+1]; int mx_use[MXVAL+1]; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cin >> n >> target; if (abs(target) > MXVAL) { cout << "impossible\n"; return 0; } fill(mx_use, mx_use+MXVAL+1, -1); mx_use[0] = 0; for (int i = 0; i <= 2*n; i++) cin >> cnt[i]; if (target < 0) { target *= -1; for (int i = 0; i < n; i++) swap(cnt[i], cnt[2*n-i]); } for (int j = 1; j <= n; j++) { for (int i = MXVAL; i >= j; i--) { for (int p = 1; (p <= cnt[n+j]) && (i-p*j >= 0); p++) if (mx_use[i-p*j] >= 0) mx_use[i] = max(mx_use[i], mx_use[i-p*j]+p); } } for (int j = 1; j <= n; j++) { for (int i = target; i <= MXVAL-j; i++) { for (int p = 1; (p <= cnt[n-j]) && (i+p*j <= MXVAL); p++) if (mx_use[i+p*j] >= 0) mx_use[i] = max(mx_use[i], mx_use[i+p*j]+p); } } if (mx_use[target] == -1) { cout << "impossible\n"; return 0; } cout << (mx_use[target]+cnt[n]) << "\n"; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...