제출 #693096

#제출 시각아이디문제언어결과실행 시간메모리
693096josanneo22Gap (APIO16_gap)C++17
30 / 100
44 ms1872 KiB
#include<bits/stdc++.h>
#include<iostream>
#include<stdlib.h>
#include<cmath>
#include <algorithm>
#include<numeric>
using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pair<int, int> > vpii;
typedef pair<ll, ll> pll;
typedef vector<pll> vpll;
typedef vector<ll> vll;
#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define trav(a,x) for (auto& a: x)
#define fr(i, a, b, s) for (int i=(a); (s)>0?i<(b):i>=(b); i+=(s))
#define fr1(e) fr(i, 0, e, 1)
#define fr2(i, e) fr(i, 0, e, 1)
#define fr3(i, b, e) fr(i, b, e, 1)
#define mp make_pair
#define pb push_back
#define sz(x) int(x.size())
#define all(x) begin(x), end(x)
#define rall(x) rbegin(x), rend(x)
#define in insert
#define yes cout<<"YES\n"
#define no cout<<"NO\n"
int dx[4] = { -1, 0, 1, 0 };
int dy[4] = { 0, 1, 0, -1 };
const int mod = 1e9 + 7;

void xd(string str)
{
	ios_base::sync_with_stdio(0); cin.tie(0);
	if (str != "")
	{
		//freopen((str + ".in").c_str(), "r", stdin);
		//freopen((str + ".out").c_str(), "w", stdout);
	}
}
int add(int a, int b, int mod = 1e9 + 7) { return (((a % mod) + (b % mod)) + mod) % mod; }
int sub(int a, int b, int mod = 1e9 + 7) { return (((a % mod) - (b % mod)) + mod) % mod; }
int mul(int a, int b, int mod = 1e9 + 7) { return (((a % mod) * (b % mod)) + mod) % mod; }
int bin(int a, int b, int mod = 1e9 + 7) { int ans = 1; while (b) { if (b & 1) ans = mul(ans, a, mod); a = mul(a, a, mod); b >>= 1; }return ans; }
int inverse(int a, int mod = 1e9 + 7) { return bin(a, mod - 2, mod); }
int divi(int a, int b, int mod = 1e9 + 7) {
	return mul(a, inverse(b, mod), mod);
}
ll add(ll a, ll b, ll mod = 1e9 + 7) { return (((a % mod) + (b % mod)) + mod) % mod; }
ll sub(ll a, ll b, ll mod = 1e9 + 7) { return (((a % mod) - (b % mod)) + mod) % mod; }
ll mul(ll a, ll b, ll mod = 1e9 + 7) { return (((a % mod) * (b % mod)) + mod) % mod; }
ll bin(ll a, ll b, ll mod = 1e9 + 7) { ll ans = 1; while (b) { if (b & 1) ans = mul(ans, a, mod); a = mul(a, a, mod); b >>= 1; }return ans; }
ll inverse(ll a, ll mod = 1e9 + 7) { return bin(a, mod - 2, mod); }
ll divi(ll a, ll b, ll mod = 1e9 + 7) {
	return mul(a, inverse(b, mod), mod);
}
ll ex(int base, int power)
{
	if (power == 0)
		return 1;
	ll result = ex(base, power / 2);
	if (power % 2 == 1)
		return(((result * result) % mod) * base) % mod;
	else return (result * result) % mod;
}
int gcd(int a, int b) {
	if (b == 0)return a;
	else return gcd(b, a % b);
}
int lcm(int a, int b) {
	return a * b / gcd(a, b);
}
ll fac(int x) {
	ll factorial = 1;
	for (ll i = 1; i <= x; ++i) {
		factorial = mul(factorial, i);
	}
	return factorial % mod;
}
ll npr(int x, int c) {
	if (x == c) return fac(x);
	else return (fac(x) / (fac(x - c) * fac(c))) % mod;
}
void bton(string s) { stoll(s, nullptr, 2); }
inline int read() {
	int x = 0, f = 1, c = getchar();
	while (!isdigit(c)) { if (c == '-')f = -1; c = getchar(); }
	while (isdigit(c)) { x = (x << 1) + (x << 3) + (c ^ 48); c = getchar(); }
	return f == 1 ? x : -x;
}
bool isPrime(int n)
{
	if (n == 2 || n == 3)
		return true;

	if (n <= 1 || n % 2 == 0 || n % 3 == 0)
		return false;
	for (int i = 5; i * i <= n; i += 6) {
		if (n % i == 0 || n % (i + 2) == 0)
			return false;
	}

	return true;
}

/*
	first we can find a[0] and a[n-1] using the range 0,1e18+1 because a[0]>0 && a[n-1]<1e18+1
	then using that we can find a[1] by using a[0] because we know that a[1]>=a[0]+1 same for a[n-2]<=a[n-1]-1
	so can use MinMax once so that a[0] and a[n-1] is defined, then we can move into the middle so that we can recold {a[1],a[n-2]},{a[2],a[n-3]},....
	this solution will be n/2
*/
#include "gap.h"

long long findGap(int t, int n)
{
	ll l = 0, r = 0;
	vll a(n);
	MinMax(0, 1e18 + 1, &l, &r);
	a[0] = l; a[n - 1] = r;
	int lp = 1, rp = n - 2;
	while (lp <= rp) {
		MinMax(a[lp-1]+1, a[rp+1]-1, &l, &r);
		a[lp] = l; a[rp] = r;
		lp++; rp--;
	}
	ll mx = 0;
	FOR(i, 1, n) {
		mx = max(mx, a[i] - a[i - 1]);
	}
	return mx;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...