# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
528599 |
2022-02-20T16:52:48 Z |
CSQ31 |
Akcija (COCI21_akcija) |
C++17 |
|
5000 ms |
63436 KB |
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define se second
#define sz(a) (int)(a.size())
#define all(a) a.begin(),a.end()
#define lb lower_bound
#define ub upper_bound
#define owo ios_base::sync_with_stdio(0);cin.tie(0);
#define INF (ll)(1e18)
#define debug(...) fprintf(stderr, __VA_ARGS__),fflush(stderr)
#define time__(d) for(long blockTime = 0; (blockTime == 0 ? (blockTime=clock()) != 0 : false);\
debug("%s time : %.4fs\n", d, (double)(clock() - blockTime) / CLOCKS_PER_SEC))
typedef long long int ll;
typedef long double ld;
typedef pair<ll,ll> PII;
typedef pair<int,int> pii;
typedef vector<vector<int>> vii;
typedef vector<vector<ll>> VII;
int n,k;
vector<PII>ans;
PII v[2005],dp[2005][2005];
PII s(int i,int j){
if(i==n)return {0,0};
if(dp[i][j] != PII(-1,-1))return dp[i][j];
PII res = s(i+1,j);
if(v[i].fi > j){
PII tmp = s(i+1,j+1);
tmp.fi++;
tmp.se+=v[i].se;
res = max(tmp,res);
}
return dp[i][j] = res;
}
void search(int i,int j,ll cnt,ll val){
if(i==n){
if(PII(cnt,val) < PII(0,0))ans.pb({cnt,val});
return;
}
PII res = s(i,j);
if(s(i,j) < PII(cnt,val))return;
search(i+1,j,cnt,val);
if(sz(ans) == k)return;
if(v[i].fi > j)search(i+1,j+1,cnt-1,val-v[i].se);
}
int main()
{
cin>>n>>k;
for(int i=0;i<n;i++){
cin>>v[i].se>>v[i].fi;
v[i].se = 1e9-v[i].se;
}
sort(v,v+n);
//for(int i=0;i<n;i++)cout<<v[i].fi<<" "<<v[i].se<<'\n';
memset(dp,-1,sizeof(dp));
ll mxv = 2e9*2000;
ll l=-1,r=2e16;
while(r-l>1){
ll mid = r+l>>1;
ll cnt = mid/mxv,val = mid%mxv;
search(0,0,cnt,val);
//cout<<cnt<<" "<<val<<" "<<sz(ans)<<'\n';
if(sz(ans) < k)r=mid;
else l=mid;
ans.clear();
}
ll cnt = r/mxv,val = r%mxv;
search(0,0,cnt,val);
while(sz(ans)<k)ans.pb({0,0});
sort(all(ans));
for(PII &x:ans){
x.fi = cnt - x.fi;
x.se = x.fi * 1e9 + x.se - val;
}
for(auto x:ans)cout<<x.fi<<" "<<x.se<<'\n';
}
Compilation message
Main.cpp: In function 'void search(int, int, ll, ll)':
Main.cpp:42:6: warning: variable 'res' set but not used [-Wunused-but-set-variable]
42 | PII res = s(i,j);
| ^~~
Main.cpp: In function 'int main()':
Main.cpp:61:13: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
61 | ll mid = r+l>>1;
| ~^~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
5091 ms |
63308 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
5091 ms |
63308 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
55 ms |
63284 KB |
Output is correct |
2 |
Correct |
67 ms |
63356 KB |
Output is correct |
3 |
Correct |
53 ms |
63344 KB |
Output is correct |
4 |
Correct |
52 ms |
63272 KB |
Output is correct |
5 |
Correct |
56 ms |
63264 KB |
Output is correct |
6 |
Correct |
26 ms |
63308 KB |
Output is correct |
7 |
Correct |
27 ms |
63436 KB |
Output is correct |
8 |
Correct |
29 ms |
63300 KB |
Output is correct |
9 |
Correct |
29 ms |
63332 KB |
Output is correct |
10 |
Correct |
34 ms |
63284 KB |
Output is correct |
11 |
Correct |
25 ms |
63116 KB |
Output is correct |
12 |
Correct |
24 ms |
63140 KB |
Output is correct |
13 |
Correct |
25 ms |
63092 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
27 ms |
63284 KB |
Output is correct |
2 |
Correct |
29 ms |
63284 KB |
Output is correct |
3 |
Correct |
28 ms |
63196 KB |
Output is correct |
4 |
Correct |
28 ms |
63292 KB |
Output is correct |
5 |
Correct |
28 ms |
63300 KB |
Output is correct |
6 |
Correct |
25 ms |
63180 KB |
Output is correct |
7 |
Correct |
26 ms |
63292 KB |
Output is correct |
8 |
Correct |
27 ms |
63308 KB |
Output is correct |
9 |
Correct |
29 ms |
63244 KB |
Output is correct |
10 |
Correct |
25 ms |
63180 KB |
Output is correct |
11 |
Correct |
25 ms |
63192 KB |
Output is correct |
12 |
Correct |
26 ms |
63112 KB |
Output is correct |
13 |
Correct |
34 ms |
63260 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
35 ms |
63172 KB |
Output is correct |
2 |
Correct |
27 ms |
63180 KB |
Output is correct |
3 |
Correct |
27 ms |
63160 KB |
Output is correct |
4 |
Correct |
27 ms |
63148 KB |
Output is correct |
5 |
Correct |
27 ms |
63180 KB |
Output is correct |
6 |
Correct |
28 ms |
63168 KB |
Output is correct |
7 |
Correct |
26 ms |
63184 KB |
Output is correct |
8 |
Correct |
34 ms |
63196 KB |
Output is correct |
9 |
Correct |
27 ms |
63196 KB |
Output is correct |
10 |
Correct |
31 ms |
63200 KB |
Output is correct |
11 |
Correct |
29 ms |
63116 KB |
Output is correct |
12 |
Correct |
33 ms |
63192 KB |
Output is correct |
13 |
Correct |
27 ms |
63120 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
5091 ms |
63308 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |