답안 #521479

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
521479 2022-02-02T08:28:28 Z errorgorn Akcija (COCI21_akcija) C++17
110 / 110
2962 ms 63612 KB
// Super Idol的笑容
//    都没你的甜
//  八月正午的阳光
//    都没你耀眼
//  热爱105°C的你
// 滴滴清纯的蒸馏水

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/rope>
using namespace std;
using namespace __gnu_pbds;
using namespace __gnu_cxx;
#define ll long long
#define ii pair<ll,ll>
#define iii pair<ii,ll>
#define fi first
#define se second
#define endl '\n'
#define debug(x) cout << #x << ": " << x << endl

#define pub push_back
#define pob pop_back
#define puf push_front
#define pof pop_front
#define lb lower_bound
#define ub upper_bound

#define rep(x,start,end) for(auto x=(start)-((start)>(end));x!=(end)-((start)>(end));((start)<(end)?x++:x--))
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()

#define indexed_set tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update>
//change less to less_equal for non distinct pbds, but erase will bug

mt19937 rng(chrono::system_clock::now().time_since_epoch().count());

int n,k;
ii arr[2005];
ll w[2005];
ll d[2005];

ii memo[2005][2005];
ii dp(int i,int j){
	if (i==n) return {0,0};
	if (memo[i][j]!=ii(-1,-1)) return memo[i][j];
	
	ii res=dp(i+1,j);
	if (j<d[i]){
		ii temp=dp(i+1,j+1);
		temp.fi++,temp.se+=w[i];
		res=max(res,temp);
	}
	
	return memo[i][j]=res;
}

vector<ii> ans;
void search(int i,int j,ll num,ll tot){
	if (i==n){
		if (ii(num,tot)<ii(0,0)) ans.pub({num,tot});
		return;
	}
	
	if (dp(i,j)<=ii(num,tot)) return;
	
	search(i+1,j,num,tot);
	if (sz(ans)==k) return;
	if (j<d[i]) search(i+1,j+1,num-1,tot-w[i]);
}

bool smaller(ll num,ll tot){
	ans.clear();
	search(0,0,num,tot);
	
	return sz(ans)<k;
}

int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	cin.exceptions(ios::badbit | ios::failbit);
	
	cin>>n>>k;
	
	const int pad=1e9;
	rep(x,0,n) cin>>arr[x].fi>>arr[x].se;
	sort(arr,arr+n,[](ii i,ii j){
		return i.se<j.se;
	});
	
	rep(x,0,n) tie(w[x],d[x])=arr[x];
	rep(x,0,n) w[x]=pad-w[x];
	
	memset(memo,-1,sizeof(memo));
	
	ll hi=2e16,lo=-1,mi;
	ll mxw=2e9*2000;
	
	while (hi-lo>1){
		mi=hi+lo>>1;
		
		ll num=mi/mxw,tot=mi%mxw;
		if (smaller(num,tot)) hi=mi;
		else lo=mi;
	}
	
	ll num=hi/mxw,tot=hi%mxw;
	//cout<<"debug: "<<num<<" "<<tot<<endl;
	
	ans.clear();
	search(0,0,num,tot);
	
	for (auto &it:ans) it={num-it.fi,tot-it.se};
	
	sort(all(ans));
	reverse(all(ans));
	
	while (sz(ans)<k) ans.pub({num,tot});
	
	for (auto &it:ans){
		cout<<it.fi<<" "<<it.fi*pad-it.se<<endl;
	}
}

Compilation message

Main.cpp: In function 'int main()':
Main.cpp:103:8: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
  103 |   mi=hi+lo>>1;
      |      ~~^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 103 ms 63448 KB Output is correct
2 Correct 67 ms 63440 KB Output is correct
3 Correct 72 ms 63416 KB Output is correct
4 Correct 55 ms 63464 KB Output is correct
5 Correct 75 ms 63400 KB Output is correct
6 Correct 25 ms 63436 KB Output is correct
7 Correct 33 ms 63440 KB Output is correct
8 Correct 26 ms 63444 KB Output is correct
9 Correct 27 ms 63400 KB Output is correct
10 Correct 34 ms 63460 KB Output is correct
11 Correct 25 ms 63168 KB Output is correct
12 Correct 24 ms 63208 KB Output is correct
13 Correct 30 ms 63132 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 103 ms 63448 KB Output is correct
2 Correct 67 ms 63440 KB Output is correct
3 Correct 72 ms 63416 KB Output is correct
4 Correct 55 ms 63464 KB Output is correct
5 Correct 75 ms 63400 KB Output is correct
6 Correct 25 ms 63436 KB Output is correct
7 Correct 33 ms 63440 KB Output is correct
8 Correct 26 ms 63444 KB Output is correct
9 Correct 27 ms 63400 KB Output is correct
10 Correct 34 ms 63460 KB Output is correct
11 Correct 25 ms 63168 KB Output is correct
12 Correct 24 ms 63208 KB Output is correct
13 Correct 30 ms 63132 KB Output is correct
14 Correct 59 ms 63456 KB Output is correct
15 Correct 58 ms 63388 KB Output is correct
16 Correct 59 ms 63460 KB Output is correct
17 Correct 56 ms 63464 KB Output is correct
18 Correct 72 ms 63476 KB Output is correct
19 Correct 28 ms 63508 KB Output is correct
20 Correct 34 ms 63468 KB Output is correct
21 Correct 34 ms 63420 KB Output is correct
22 Correct 30 ms 63436 KB Output is correct
23 Correct 39 ms 63464 KB Output is correct
24 Correct 34 ms 63144 KB Output is correct
25 Correct 30 ms 63212 KB Output is correct
26 Correct 33 ms 63156 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 79 ms 63440 KB Output is correct
2 Correct 71 ms 63452 KB Output is correct
3 Correct 73 ms 63380 KB Output is correct
4 Correct 70 ms 63556 KB Output is correct
5 Correct 68 ms 63360 KB Output is correct
6 Correct 27 ms 63456 KB Output is correct
7 Correct 33 ms 63528 KB Output is correct
8 Correct 29 ms 63500 KB Output is correct
9 Correct 40 ms 63460 KB Output is correct
10 Correct 35 ms 63456 KB Output is correct
11 Correct 33 ms 63208 KB Output is correct
12 Correct 25 ms 63172 KB Output is correct
13 Correct 28 ms 63172 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 38 ms 63320 KB Output is correct
2 Correct 30 ms 63356 KB Output is correct
3 Correct 29 ms 63344 KB Output is correct
4 Correct 30 ms 63272 KB Output is correct
5 Correct 32 ms 63340 KB Output is correct
6 Correct 32 ms 63240 KB Output is correct
7 Correct 30 ms 63320 KB Output is correct
8 Correct 36 ms 63308 KB Output is correct
9 Correct 30 ms 63292 KB Output is correct
10 Correct 26 ms 63204 KB Output is correct
11 Correct 26 ms 63140 KB Output is correct
12 Correct 26 ms 63168 KB Output is correct
13 Correct 32 ms 63308 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 28 ms 63168 KB Output is correct
2 Correct 31 ms 63240 KB Output is correct
3 Correct 28 ms 63184 KB Output is correct
4 Correct 29 ms 63236 KB Output is correct
5 Correct 35 ms 63220 KB Output is correct
6 Correct 27 ms 63252 KB Output is correct
7 Correct 28 ms 63180 KB Output is correct
8 Correct 26 ms 63148 KB Output is correct
9 Correct 26 ms 63192 KB Output is correct
10 Correct 27 ms 63160 KB Output is correct
11 Correct 26 ms 63204 KB Output is correct
12 Correct 33 ms 63136 KB Output is correct
13 Correct 30 ms 63124 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 103 ms 63448 KB Output is correct
2 Correct 67 ms 63440 KB Output is correct
3 Correct 72 ms 63416 KB Output is correct
4 Correct 55 ms 63464 KB Output is correct
5 Correct 75 ms 63400 KB Output is correct
6 Correct 25 ms 63436 KB Output is correct
7 Correct 33 ms 63440 KB Output is correct
8 Correct 26 ms 63444 KB Output is correct
9 Correct 27 ms 63400 KB Output is correct
10 Correct 34 ms 63460 KB Output is correct
11 Correct 25 ms 63168 KB Output is correct
12 Correct 24 ms 63208 KB Output is correct
13 Correct 30 ms 63132 KB Output is correct
14 Correct 59 ms 63456 KB Output is correct
15 Correct 58 ms 63388 KB Output is correct
16 Correct 59 ms 63460 KB Output is correct
17 Correct 56 ms 63464 KB Output is correct
18 Correct 72 ms 63476 KB Output is correct
19 Correct 28 ms 63508 KB Output is correct
20 Correct 34 ms 63468 KB Output is correct
21 Correct 34 ms 63420 KB Output is correct
22 Correct 30 ms 63436 KB Output is correct
23 Correct 39 ms 63464 KB Output is correct
24 Correct 34 ms 63144 KB Output is correct
25 Correct 30 ms 63212 KB Output is correct
26 Correct 33 ms 63156 KB Output is correct
27 Correct 79 ms 63440 KB Output is correct
28 Correct 71 ms 63452 KB Output is correct
29 Correct 73 ms 63380 KB Output is correct
30 Correct 70 ms 63556 KB Output is correct
31 Correct 68 ms 63360 KB Output is correct
32 Correct 27 ms 63456 KB Output is correct
33 Correct 33 ms 63528 KB Output is correct
34 Correct 29 ms 63500 KB Output is correct
35 Correct 40 ms 63460 KB Output is correct
36 Correct 35 ms 63456 KB Output is correct
37 Correct 33 ms 63208 KB Output is correct
38 Correct 25 ms 63172 KB Output is correct
39 Correct 28 ms 63172 KB Output is correct
40 Correct 38 ms 63320 KB Output is correct
41 Correct 30 ms 63356 KB Output is correct
42 Correct 29 ms 63344 KB Output is correct
43 Correct 30 ms 63272 KB Output is correct
44 Correct 32 ms 63340 KB Output is correct
45 Correct 32 ms 63240 KB Output is correct
46 Correct 30 ms 63320 KB Output is correct
47 Correct 36 ms 63308 KB Output is correct
48 Correct 30 ms 63292 KB Output is correct
49 Correct 26 ms 63204 KB Output is correct
50 Correct 26 ms 63140 KB Output is correct
51 Correct 26 ms 63168 KB Output is correct
52 Correct 32 ms 63308 KB Output is correct
53 Correct 28 ms 63168 KB Output is correct
54 Correct 31 ms 63240 KB Output is correct
55 Correct 28 ms 63184 KB Output is correct
56 Correct 29 ms 63236 KB Output is correct
57 Correct 35 ms 63220 KB Output is correct
58 Correct 27 ms 63252 KB Output is correct
59 Correct 28 ms 63180 KB Output is correct
60 Correct 26 ms 63148 KB Output is correct
61 Correct 26 ms 63192 KB Output is correct
62 Correct 27 ms 63160 KB Output is correct
63 Correct 26 ms 63204 KB Output is correct
64 Correct 33 ms 63136 KB Output is correct
65 Correct 30 ms 63124 KB Output is correct
66 Correct 1402 ms 63560 KB Output is correct
67 Correct 1844 ms 63540 KB Output is correct
68 Correct 1698 ms 63528 KB Output is correct
69 Correct 1429 ms 63528 KB Output is correct
70 Correct 2962 ms 63556 KB Output is correct
71 Correct 970 ms 63584 KB Output is correct
72 Correct 304 ms 63612 KB Output is correct
73 Correct 222 ms 63580 KB Output is correct
74 Correct 565 ms 63568 KB Output is correct
75 Correct 1279 ms 63520 KB Output is correct
76 Correct 26 ms 63220 KB Output is correct
77 Correct 27 ms 63212 KB Output is correct
78 Correct 45 ms 63328 KB Output is correct