답안 #1036463

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1036463 2024-07-27T11:53:21 Z Alihan_8 커다란 상품 (IOI17_prize) C++17
0 / 100
8 ms 5208 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];
	};
	
	int mx = -1, k = -1;
	
	for ( int i = 0; i < min(n, B); i++ ){
		auto c = f(i);
		
		int x = c[0] + c[1];
		
		if ( chmax(mx, x) || mx == x ){
			k = i;
		}
		
		if ( x == 0 ){
			return i;
		}
	}
	
	while ( k < n ){
		int l = k, r = min(n, k + B) - 1;
		
		if ( f(l) == f(r) ){
			k += B;
			
			continue;
		}
		
		while ( l + 1 < r ){
			int m = (l + r) / 2;
			
			if ( f(m) != f(k) ){
				r = m;
			} else l = m;
		}
		
		for ( int i = r; i < min(n, i + B); i++ ){
			if ( f(i)[0] + f(i)[1] == 0 ){
				return i;
			}
		}
		
		k += B;
	}
	
	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 4952 KB Output is correct
2 Correct 6 ms 4952 KB Output is correct
3 Correct 7 ms 4952 KB Output is correct
4 Incorrect 8 ms 4952 KB answer is not correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 5208 KB Output is correct
2 Correct 5 ms 5152 KB Output is correct
3 Correct 5 ms 4952 KB Output is correct
4 Incorrect 6 ms 4952 KB answer is not correct
5 Halted 0 ms 0 KB -