# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
278029 | 2020-08-21T09:02:58 Z | 반딧불(#5119) | Shopping Plans (CCO20_day2problem3) | C++17 | 4000 ms | 655764 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]; 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]; } for(int i=0; i<m; i++){ weight[i] = rand(); } vector<int> zeroVec (m, 0); 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; if(!tmp.b) tv = zeroVec; else{ tv = ansVec[tmp.b]; tv[tmp.c]++; } ansVec[d] = tv; ans[d] = tmp.a; for(int i=0; i<m; i++){ if(tv[i] == (int)arr[i+1].size()-1) 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
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 2914 ms | 323828 KB | Output is correct |
2 | Correct | 2310 ms | 252520 KB | Output is correct |
3 | Correct | 2932 ms | 316612 KB | Output is correct |
4 | Correct | 473 ms | 73148 KB | Output is correct |
5 | Correct | 2898 ms | 324912 KB | Output is correct |
6 | Execution timed out | 4057 ms | 469160 KB | Time limit exceeded |
7 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Runtime error | 3119 ms | 655764 KB | Execution killed with signal 11 |
2 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 2914 ms | 323828 KB | Output is correct |
2 | Correct | 2310 ms | 252520 KB | Output is correct |
3 | Correct | 2932 ms | 316612 KB | Output is correct |
4 | Correct | 473 ms | 73148 KB | Output is correct |
5 | Correct | 2898 ms | 324912 KB | Output is correct |
6 | Execution timed out | 4057 ms | 469160 KB | Time limit exceeded |
7 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Incorrect | 9 ms | 1164 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 2914 ms | 323828 KB | Output is correct |
2 | Correct | 2310 ms | 252520 KB | Output is correct |
3 | Correct | 2932 ms | 316612 KB | Output is correct |
4 | Correct | 473 ms | 73148 KB | Output is correct |
5 | Correct | 2898 ms | 324912 KB | Output is correct |
6 | Execution timed out | 4057 ms | 469160 KB | Time limit exceeded |
7 | Halted | 0 ms | 0 KB | - |