제출 #1049206

#제출 시각아이디문제언어결과실행 시간메모리
1049206DeathIsAweXylophone (JOI18_xylophone)C++17
0 / 100
0 ms344 KiB
#include "xylophone.h" #include <bits/stdc++.h> using namespace std; int a[5001]; bool solved[5001]; void solve(int n) { for (int i=0;i<5001;i++) { a[i] = -1; solved[i] = false; } int bottom = 1, top = n, middle, diff, diff2; while (bottom + 1 < top) { middle = (top + bottom) / 2; diff = query(1, middle); if (diff == n - 1) { top = middle; } else { bottom = middle; } } a[top] = n; solved[n] = true; answer(top, n); if (top != n) { a[top + 1] = n - query(top, top + 1); solved[a[top + 1]] = true; answer(top + 1, a[top + 1]); } a[top - 1] = n - query(top - 1, top); solved[a[top - 1]] = true; answer(top - 1, a[top - 1]); for (int i=top+2;i<n+1;i++) { diff = query(i - 1, i); if (a[i - 1] - diff < 1 || solved[a[i - 1] - diff]) { a[i] = a[i - 1] + diff; } else if (a[i - 1] + diff > n || solved[a[i - 1] + diff]) { a[i] = a[i - 1] - diff; } else { diff2 = query(i - 2, i); if (a[i - 2] > a[i - 1]) { if (diff2 == a[i - 2] - a[i - 1] + diff) { a[i] = a[i - 1] - diff; } else { a[i] = a[i - 1] + diff; } } else { if (diff2 == a[i - 1] - a[i - 2] + diff) { a[i] = a[i - 1] + diff; } else { a[i] = a[i - 1] - diff; } } } solved[a[i]] = true; answer(i, a[i]); } for (int i=top-2;i>0;i--) { diff = query(i, i + 1); if (a[i + 1] - diff < 1 || solved[a[i - 1] - diff]) { a[i] = a[i + 1] + diff; } else if (a[i + 1] + diff > n || solved[a[i + 1] + diff]) { a[i] = a[i + 1] - diff; } else { diff2 = query(i, i + 2); if (a[i + 2] > a[i + 1]) { if (diff2 == a[i + 2] - a[i + 1] + diff) { a[i] = a[i + 1] - diff; } else { a[i] = a[i + 1] + diff; } } else { if (diff2 == a[i + 1] - a[i + 2] + diff) { a[i] = a[i + 1] + diff; } else { a[i] = a[i + 1] - diff; } } } solved[a[i]] = true; answer(i, a[i]); } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...