# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
278008 | 2020-08-21T08:37:51 Z | 반딧불(#5119) | Shopping Plans (CCO20_day2problem3) | C++17 | 2341 ms | 1048580 KB |
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<ll, vector<int> > pivi; int n, m, k; vector<ll> arr[200002]; priority_queue<pivi> pq; ll ans[200002]; set<ll> st; ll sum = 0; ll hsh(vector<int>& v){ ll ret = 0; for(auto &x: v) ret *= 26137, ret += x, ret %= 1000000007; return ret; } 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]; } vector<int> zeroVec (m, 0); pq.push({-sum, zeroVec}); st.insert(hsh(zeroVec)); for(int d=1; d<=k; d++){ if(pq.empty()) break; auto tmp = pq.top(); pq.pop(); // for(int i=0; i<m; i++) printf("%d ", tmp.second[i]); puts(""); ans[d] = -tmp.first; for(int i=0; i<m; i++){ if(tmp.second[i] == (int)arr[i+1].size()-1) continue; tmp.second[i]++; ll tsh = hsh(tmp.second); if(st.find(tsh) == st.end()) st.insert(tsh), pq.push(make_pair(-(-tmp.first + arr[i+1][tmp.second[i]] - arr[i+1][tmp.second[i]-1]), tmp.second)); tmp.second[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 | Runtime error | 2341 ms | 1048580 KB | Execution killed with signal 9 |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Runtime error | 2285 ms | 1048580 KB | Execution killed with signal 9 |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Runtime error | 2341 ms | 1048580 KB | Execution killed with signal 9 |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 13 ms | 5632 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Runtime error | 2341 ms | 1048580 KB | Execution killed with signal 9 |
2 | Halted | 0 ms | 0 KB | - |