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>
static int A[5000];
int a[5010];
int q[5010][5010];
int qur(int a, int b) {
if (q[a][b] == -1) return q[a][b] = query(a, b);
else return q[a][b];
}
void solve(int n) {
memset(q, -1, sizeof q);
int fir = qur(1, 2);
for (int x = 1; x <= n; x++) {
a[1] = x;
for (int typ = -1; typ < 2; typ += 2) {
a[2] = fir * typ + x;
for (int i = 3; i <= n; i++) {
int x = qur(i - 1, i);
int y = qur(i - 2, i);
if (a[i - 1] < a[i - 2]) {
if (y == a[i - 2] - a[i - 1] + x) a[i] = a[i - 1] - x;
else if (x == y) a[i] = a[i - 1] + x;
else a[i] = a[i - 1] + x;
} else {
if (y == a[i - 1] - a[i - 2]) a[i] = a[i - 1] - x;
else if (x == y) a[i] = a[i - 1] - x;
else a[i] = a[i - 1] + x;
}
}
int s = -1;
bool flag = false;
for (int i = 1; i <= n; i++) {
if (a[i] == 1) s = i;
else if (a[i] == n) {
if (s != -1) flag = true;
else flag = false;
} else if (a[i] > n) {
flag = false;
break;
}
}
/**
for (int i = 1; i <= n; i++)
printf("%d ", a[i]);
printf("\n");
**/
if (flag) {
//printf("debug: ");
//for (int i = 1; i <= n; i++)
// printf("%d ", a[i]);
//printf("\n");
for (int i = 1; i <= n; i++)
answer(i, a[i]);
return;
}
}
}
}
Compilation message (stderr)
xylophone.cpp:4:12: warning: 'A' defined but not used [-Wunused-variable]
static int A[5000];
^
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |