답안 #1036312

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1036312 2024-07-27T08:37:45 Z Alihan_8 커다란 상품 (IOI17_prize) C++17
0 / 100
5 ms 4952 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;
			} 
		}
		
		int l = k, r = n;
		
		while ( l + 1 < r ){
			int m = (l + r) / 2;
			
			if ( f(m) != opt ){
				r = m;
			} else l = m;
		}
		
		i = l;
	}
}

Compilation message

prize.cpp: In function 'int find_best(int)':
prize.cpp:36:27: warning: control reaches end of non-void function [-Wreturn-type]
   36 |  vector <vector<int>> dp(n);
      |                           ^
# 결과 실행 시간 메모리 Grader output
1 Runtime error 5 ms 4952 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 5 ms 4952 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -