Submission #416978

#TimeUsernameProblemLanguageResultExecution timeMemory
416978maomao90A Difficult(y) Choice (BOI21_books)C++17
100 / 100
2 ms328 KiB
    #include <bits/stdc++.h> 
    #include "books.h"
    using namespace std;
     
    #define mnto(x, y) x = min(x, (__typeof__(x)) y)
    #define mxto(x, y) x = max(x, (__typeof__(x)) y)
    #define REP(i, s, e) for (int i = s; i < e; i++)
    #define RREP(i, s, e) for (int i = s; i >= e; i--)
    typedef long long ll;
    typedef long double ld;
    #define MP make_pair
    #define FI first
    #define SE second
    typedef pair<int, int> ii;
    typedef pair<ll, ll> pll;
    #define MT make_tuple
    typedef tuple<int, int, int> iii;
    #define ALL(_a) _a.begin(), _a.end()
    #define pb emplace_back
    typedef vector<int> vi;
    typedef vector<ii> vii;
     
    #define INF 1000000005
    #define LINF 1000000000000000005
    #define MOD 1000000007
    #define MAXN 100005
     
    ll x[MAXN];
    int todo[15];
     
    void solve(int n, int k, ll a, int s) {
    	ll small = 0;
    	REP (i, 1, k + 1) {
    		x[i] = skim(i);
    		small += x[i];
    	}
    	REP (i, 1, k + 1) {
    		todo[i] = i;
    	}
    	if (small > 2 * a) {
    	   	impossible();
    		return;
    	}
    	if (small >= a) {
    		vi ans;
    		REP (i, 1, k + 1) {
    			ans.pb(i);
    		}
    		answer(ans);
    		return;
    	}
    	int lo = 1, hi = n, mid;
    	while (lo <= hi) {
    		mid = hi + lo >> 1;
    		if (x[mid] == 0) x[mid] = skim(mid);
    		if (x[mid] < a) {
    			lo = mid + 1;
    		} else {
    			hi = mid - 1;
    		}
    	}
    	REP (i, lo - k, lo) {
    		x[i] = skim(i);
    	}
    	RREP (i, k, 1) {
    		small -= x[i];
    		int id = lo - (k - i) - 1;
    		small += x[id];
    		todo[i] = id;
    		if (small >= a) {
    			vi ans;
    			REP (i, 1, k + 1) {
    				ans.pb(todo[i]);
    			}
    			answer(ans);
    			return;
    		}
    	}
    	if (x[lo] == 0) x[lo] = skim(lo);
    	REP (i, 1, k) {
    		todo[i] = i;
    	}
    	todo[k] = lo;
    	small = 0;
    	REP (i, 1, k + 1) {
    		small += x[todo[i]];
    	}
    	if (small >= a && small <= 2 * a) {
    		vi ans;
    		REP (i, 1, k + 1) {
    			ans.pb(todo[i]);
    		}
    		answer(ans);
    		return;
    	}
    	impossible();
    }

Compilation message (stderr)

books.cpp: In function 'void solve(int, int, ll, int)':
books.cpp:54:16: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   54 |       mid = hi + lo >> 1;
      |             ~~~^~~~
#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...