# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
278031 | 2020-08-21T09:04:53 Z | 반딧불(#5119) | Shopping Plans (CCO20_day2problem3) | C++17 | 1644 ms | 380228 KB |
#include <bits/stdc++.h> #pragma GCC target("avx2") #pragma GCC optimize("Ofast") #pragma GCC optimize("unroll-loops") using namespace std; typedef long long ll; struct dat{ ll a, b, c, d; dat(ll a, ll b, ll c, ll d): a(a), b(b), c(c), d(d){} bool operator<(const dat &r)const{ return a>r.a; } }; int n, m, k; vector<ll> arr[4002]; int len[4002]; priority_queue<dat> pq; ll ans[4002]; ll weight[4002]; vector<int> ansVec[4002]; unordered_set<ll> st; ll sum = 0; int main(){ scanf("%d %d %d", &n, &m, &k); for(int i=1; i<=n; i++){ int x; ll y; scanf("%d %lld", &x, &y); arr[x].push_back(y); } for(int i=1; i<=m; i++){ int x, y; scanf("%d %d", &x, &y); } for(int i=1; i<=m; i++) sort(arr[i].begin(), arr[i].end()); for(int i=1; i<=m; i++){ if(arr[i].empty()){ while(k--) printf("-1\n"); return 0; } sum += arr[i][0]; len[i] = (int)arr[i].size()-1; } for(int i=0; i<m; i++){ weight[i] = rand(); } st.insert(0); pq.push(dat(sum, 0, 0, 0)); for(int d=1; d<=k; d++){ // printf("%d ", d); if(pq.empty()) break; auto tmp = pq.top(); pq.pop(); vector<int> tv(m,0); if(tmp.b){ tv = ansVec[tmp.b]; tv[tmp.c]++; } ansVec[d] = tv; ans[d] = tmp.a; for(int i=0; i<m; i++){ if(tv[i] == len[i]) continue; tv[i]++; ll tsh = tmp.d + weight[i] * (arr[i+1][tv[i]] - arr[i+1][tv[i]-1]); if(st.find(tsh) == st.end()) st.insert(tsh), pq.push(dat(tmp.a + arr[i+1][tv[i]] - arr[i+1][tv[i]-1], d, i, tsh)); tv[i]--; } } for(int d=1; d<=k; d++){ printf("%lld\n", ans[d] ? ans[d] : -1); } }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 1644 ms | 175008 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Runtime error | 1622 ms | 380228 KB | Execution killed with signal 11 |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 1644 ms | 175008 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 12 ms | 1152 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 1644 ms | 175008 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |