Submission #125936

#TimeUsernameProblemLanguageResultExecution timeMemory
125936kingfran1907Xylophone (JOI18_xylophone)C++14
100 / 100
1067 ms98788 KiB
#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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...