이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
//By Don4ick
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#include "xylophone.h"
typedef long long ll;
typedef long double ld;
typedef unsigned int ui;
#define forn(i, n) for (int i = 1; i <= n; i++)
#define pb push_back
#define all(x) x.begin(), x.end()
#define y1 qwer1234
const double PI = acos(-1.0);
const int DIR = 4;
const int X[] = {1, 0, -1, 0};
const int Y[] = {0, 1, 0, -1};
using namespace std;
void solve(int n) {
int pos = -1;
int cnt = 0;
//~binary_search
{
int l = 0, r = n + 1;
while(l < r - 1)
{
int mid = (l + r) >> 1;
cnt++;
if (query(mid, n) == n - 1)
l = mid;
else
r = mid;
}
pos = l;
}
answer(pos, 1);
//~solve(1, pos)
if (pos > 1)
{
cnt++;
int y = 1, x = query(pos - 1, pos) + 1;
answer(pos - 1, x);
for (int i = pos - 2; i >= 1; i--)
{
cnt++;
assert(cnt <= 10000);
int value = query(i, i + 2);
if (value > abs(x - y))
{
cnt++;
assert(cnt <= 10000);
int newValue = query(i, i + 1);
if (x < y)
{
if (newValue == value)
{
y = x + value;
swap(x, y);
answer(i, x);
}
else
{
y = x - newValue;
swap(x, y);
answer(i, x);
}
}
else
{
if (newValue == value)
{
y = x - value;
swap(x, y);
answer(i, x);
}
else
{
y = x + newValue;
swap(x, y);
answer(i, x);
}
}
}
else
{
cnt++;
assert(cnt <= 10000);
int newValue = query(i, i + 1);
if (x < y)
{
y = x + newValue;
swap(x, y);
answer(i, x);
}
else
{
y = x - newValue;
swap(x, y);
answer(i, x);
}
}
}
}
//~solve(pos, n)
if (pos < n)
{
cnt++;
assert(cnt <= 10000);
int y = 1, x = query(pos, pos + 1) + 1;
answer(pos + 1, x);
for (int i = pos + 2; i <= n; i++)
{
cnt++;
assert(cnt <= 10000);
int value = query(i - 2, i);
if (value > abs(x - y))
{
cnt++;
assert(cnt <= 10000);
int newValue = query(i - 1, i);
if (x < y)
{
if (newValue == value)
{
y = x + value;
swap(x, y);
answer(i, x);
}
else
{
y = x - newValue;
swap(x, y);
answer(i, x);
}
}
else
{
if (newValue == value)
{
y = x - value;
swap(x, y);
answer(i, x);
}
else
{
y = x + newValue;
swap(x, y);
answer(i, x);
}
}
}
else
{
cnt++;
assert(cnt <= 10000);
int newValue = query(i - 1, i);
if (x < y)
{
y = x + newValue;
swap(x, y);
answer(i, x);
}
else
{
y = x - newValue;
swap(x, y);
answer(i, x);
}
}
}
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |