Submission #656770

#TimeUsernameProblemLanguageResultExecution timeMemory
656770ktkeremA Difficult(y) Choice (BOI21_books)C++17
0 / 100
1 ms1060 KiB
#include<bits/stdc++.h>
#include "books.h"
typedef long long ll;
typedef std::pair<ll , ll> llll;
typedef std::string str;
#define debug std::cout << "debug" << std::endl
#define pb push_back
void solve(int n , int m ,ll a , int s){
	ll l = 1 , r = n;
	ll kp[n + 1];
	memset(kp , -1 , sizeof(kp));
	while(r > l){
		ll md = (l+r)/2;
		ll z = skim(md);
		kp[md] = z;
		if(z>=a){
			r = md;
		}
		else{
			l=md+1;
		}
	}
	ll js = l;
	ll p = 0;
	ll t = 0;
	for(ll i = 1;m > i;i++){
		if(kp[i] != -1){
			t+=kp[i];
			continue;
		}
		ll o = skim(i);
		kp[i] = o;
		t+=o;
	}
	ll ss = std::max(js - m , (ll)m+1);
	if(t + kp[js] >= a && 2 * a >= t + kp[js]){
		std::vector<int> vec;
		for(ll i = 1;m>i;i++){
			vec.pb(i);
		}
		vec.pb(js);
		answer(vec);
		return;
	}
	if(kp[m] == -1){
		kp[m] = skim(m);
	}
	t+= kp[m];
	if(t >= a && t<=2*a){
		std::vector<int> vec;
		for(ll i = 1;m>=i;i++){
			vec.pb(i);
		}
		answer(vec);
		return;
	}
	ll o = 1;
	while(o + ss <= js){
		if(kp[o + ss - 1] == -1){
			skim(o + ss -1);
		}
		t+=kp[o + ss - 1];
		t-=kp[o];
		if(t >= a && 2 * a >= t){
			std::vector<int> vec;
			for(ll i = o+1;m>=i;i++){
				vec.pb(i);
			}
			for(ll i = 0;o>i;i++){
				vec.pb(ss + i);
			}
			answer(vec);
			return;
		}
		o++;
	}
	impossible();
}
/*int main(){
	#ifndef ONLINE_JUDGE
		freopen("in.txt","r",stdin);
		freopen("out.txt","w",stdout);
	#endif
	ll t = 1;std::cin >> t;
	while(t--){
		solve();
	}
	return 0;
}*/

Compilation message (stderr)

books.cpp: In function 'void solve(int, int, ll, int)':
books.cpp:24:5: warning: unused variable 'p' [-Wunused-variable]
   24 |  ll p = 0;
      |     ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...