This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include "xylophone.h"
#include <bits/stdc++.h>
using namespace std;
template<class T>
void readi(T &x)
{
T input = 0;
bool negative = false;
char c = ' ';
while (c < '-')
{
c = getchar();
}
if (c == '-')
{
negative = true;
c = getchar();
}
while (c >= '0')
{
input = input * 10 + (c - '0');
c = getchar();
}
if (negative)
{
input = -input;
}
x = input;
}
template<class T>
void printi(T output)
{
if (output == 0)
{
putchar('0');
return;
}
if (output < 0)
{
putchar('-');
output = -output;
}
int aout[20];
int ilen = 0;
while(output)
{
aout[ilen] = ((output % 10));
output /= 10;
ilen++;
}
for (int i = ilen - 1; i >= 0; i--)
{
putchar(aout[i] + '0');
}
return;
}
template<class T>
void ckmin(T &a, T b)
{
a = min(a, b);
}
template<class T>
void ckmax(T &a, T b)
{
a = max(a, b);
}
long long randomize(long long mod)
{
return ((1ll << 30) * rand() + (1ll << 15) * rand() + rand()) % mod;
}
#define MP make_pair
#define PB push_back
#define PF push_front
#define LB lower_bound
#define UB upper_bound
#define fi first
#define se second
const long double PI = 4.0 * atan(1.0);
const long double EPS = 1e-10;
#define MAGIC 347
#define SINF 10007
#define CO 1000007
#define INF 1000000007
#define BIG 1000000931
#define LARGE 1696969696967ll
#define GIANT 2564008813937411ll
#define LLINF 2696969696969696969ll
#define MAXN 5013
long long normalize(long long x, long long mod = INF)
{
return (((x % mod) + mod) % mod);
}
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
int N;
int ans[MAXN];
int vis[MAXN][MAXN];
int get(int a, int b)
{
if (a == b) return 0;
if (a > b) swap(a, b);
if (vis[a][b])
{
return vis[a][b];
}
vis[a][b] = query(a + 1, b + 1);
return vis[a][b];
}
void solve(int n)
{
N = n;
ans[0] = 0;
ans[1] = get(0, 1);
for (int i = 2; i < N; i++)
{
int x = get(i - 2, i), y = get(i - 1, i);
int u = ans[i - 1] + y, d = ans[i - 1] - y;
int big = max(u, max(ans[i - 1], ans[i - 2]));
int small = min(u, min(ans[i - 1], ans[i - 2]));
if (big - small == x)
{
ans[i] = u;
}
else
{
ans[i] = d;
}
}
int sm = INF;
for (int i = 0; i < N; i++)
{
ckmin(sm, ans[i]);
}
for (int i = 0; i < N; i++)
{
ans[i] -= sm;
}
bool flag = false;
for (int i = 0; i < N; i++)
{
if (ans[i] == 0)
{
break;
}
if (ans[i] == N - 1)
{
flag = true;
break;
}
}
if (flag)
{
for (int i = 0; i < N; i++)
{
ans[i] = (N - 1) - ans[i];
}
}
// cerr << lo << ' ' << hi << endl;
for (int i = 0; i < N; i++)
{
answer(i + 1, ans[i] + 1);
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |