Submission #1036316

# Submission time Handle Problem Language Result Execution time Memory
1036316 2024-07-27T08:42:03 Z Alihan_8 The Big Prize (IOI17_prize) C++17
0 / 100
7 ms 10072 KB
#include "prize.h"

#include <bits/stdc++.h>

using namespace std;

#define all(x) x.begin(), x.end()
#define ar array
#define pb push_back
#define ln '\n'
//#define int long long

using i64 = long long;

template <class F, class _S>
bool chmin(F &u, const _S &v){
    bool flag = false;
    if ( u > v ){
        u = v; flag |= true;
    }
    return flag;
}

template <class F, class _S>
bool chmax(F &u, const _S &v){
    bool flag = false;
    if ( u < v ){
        u = v; flag |= true;
    }
    return flag;
}

const int B = 500;

int find_best(int n){
	vector <vector<int>> dp(n);
	
	auto f = [&](int j){
		if ( dp[j].empty() ){
			dp[j] = ask(j);
		}
		
		return dp[j][0] + dp[j][1];
	};
	
	for ( int i = 0; i < n; i++ ){
		int opt = -1, k = -1;
		
		for ( int j = i; j < min(n, i + B); j++ ){
			int x = f(j);
			
			if ( x == 0 ){
				return j;
			}
			
			if ( chmax(opt, x) || opt == x ){
				k = j;
			} 
		}
		
		assert(k != -1);
		
		int l = k, r = n;
		
		while ( l + 1 < r ){
			int m = (l + r) / 2;
			
			if ( f(m) != opt ){
				r = m;
			} else l = m;
		}
		
		i = max(i + B - 1, l);
	}
	
	assert(false);
}
# Verdict Execution time Memory Grader output
1 Runtime error 7 ms 10072 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 6 ms 10072 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -