# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
751691 | sofija6 | Xylophone (JOI18_xylophone) | C++14 | 426 ms | 456 KiB |
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;
static int A[5000];
bool check(int N)
{
bool yes=true;
int cnt[N+2]={0};
for (int j=1;j<=N;j++)
cnt[j]=0;
for (int j=1;j<=N;j++)
{
if (A[j]<=N && A[j]>=1)
{
if ((A[j]==N && !cnt[1]) || cnt[A[j]])
yes=false;
cnt[A[j]]++;
}
}
for (int j=1;j<=N;j++)
{
if (!cnt[j])
yes=false;
}
return yes;
}
void solve(int N) {
int diff2[N+2],diff3[N+2],cnt[N+2];
for (int i=1;i<N;i++)
{
if (i<N-1)
diff3[i]=query(i,i+2);
diff2[i]=query(i,i+1);
}
for (int i=1;i<=N;i++)
{
int cur=1;
A[1]=i;
for (int j=2;j<=N;j++)
{
if (j>2 && N>2 && diff3[j-2]!=diff2[j-2]+diff2[j-1])
cur*=(-1);
A[j]=A[j-1]+diff2[j-1]*cur;
}
if (check(N))
{
for (int j=1;j<=N;j++)
answer(j,A[j]);
return;
}
cur=-1;
for (int j=2;j<=N;j++)
{
if (j>2 && N>2 && diff3[j-2]!=diff2[j-2]+diff2[j-1])
cur*=(-1);
A[j]=A[j-1]+diff2[j-1]*cur;
}
if (check(N))
{
for (int j=1;j<=N;j++)
answer(j,A[j]);
return;
}
}
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |