# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
590476 | Huy | Xylophone (JOI18_xylophone) | C++17 | 0 ms | 0 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
//#define int long long
#define pii pair<int,ll>
#define fi first
#define se second
/*#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")*/
using namespace std;
using ll = long long;
using ull = unsigned long long;
using ldb = long double;
const ll N = (int)1e9 + 1;
const int maxN = (int)3e5 + 1;
const int mod = 1e9 + 7;
//const int mod = 998244353;
const ll infty = 1e18 + 7;
const int base = (int)4e5;
void InputFile()
{
//freopen("scrivener.inp","r",stdin);
//freopen("scrivener.out","w",stdout);
//freopen("test.out","r",stdin);
}
void FastInput()
{
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
}
int a[5005];
int apr[5005];
void solve(int n)
{
int low = 1;
int high = n;
while(low <= high)
{
int mid = (low + high) / 2;
int x = query(mid,n);
if(x == n - 1)
low = low = mid + 1;
else
high = mid - 1;
}
answer(high,1);
int pt = high;
a[high] = 1;
for(int i = pt - 1; i >= 1; i--)
{
int diff = query(i,i+1);
if(a[i+1] - diff < 0)
{
a[i] = a[i+1] + diff;
answer(i,a[i]);
}
else if(a[i+ 1] + diff > n)
{
a[i] = a[i+1] - diff;
answer(i,a[i]);
}
else
{
if(apr[a[i+1]-diff])
{
a[i] = a[i+1] + diff;
answer(i,a[i]);
}
else if(apr[a[i+1]+diff])
{
a[i] = a[i+1] - diff;
answer(i,a[i]);
}
else
{
int c = a[i+1] - diff;
int maxi,mini;
maxi = max(max(c,a[i+1]),a[i+2]);
mini = min(min(c,a[i+1]),a[i+2]);
if(query(i,i+1) == maxi - mini)
{
a[i] = c;
answer(i,c);
}
else answer(i,a[i+1] + diff);
}
}
apr[a[i]]++;
}
for(int i = pt + 1; i <= n; i++)
{
int diff = query(i-1,i);
if(a[i-1] - diff < 0)
{
a[i] = a[i-1] + diff;
answer(i,a[i]);
}
else if(a[i-1] + diff > n)
{
a[i] = a[i-1] - diff;
answer(i,a[i]);
}
else
{
if(apr[a[i-1]-diff])
{
a[i] = a[i-1] + diff;
answer(i,a[i]);
}
else if(apr[a[i-1]+diff])
{
a[i] = a[i-1] - diff;
answer(i,a[i]);
}
else
{
int c = a[i-1] - diff;
int maxi,mini;
maxi = max(max(c,a[i-1]),a[i-2]);
mini = min(min(c,a[i-1]),a[i-2]);
if(query(i-1,i) == maxi - mini)
{
a[i] = c;
answer(i,c);
}
else answer(i,a[i-1] + diff);
}
}
apr[a[i]]++;
}
}
void Debug()
{
}
/*int32_t main()
{
FastInput();
//InputFile();
//int sub_type;
//cin >> sub_type;
//Sieve();
//Prepare();
int test;
cin >> test;
//test = 1;
while(test--)
//for(int prc = 1; prc <= test; prc++)
{
Read();
Solve();
//Debug();
}
}*/
/*
2 5
B 0 A 4
B 1 B 3
A 5 B 7
B 2 A 6
B 1 A 7
*/