제출 #1150693

#제출 시각아이디문제언어결과실행 시간메모리
1150693minggaXylophone (JOI18_xylophone)C++20
100 / 100
26 ms432 KiB
#include "xylophone.h" #include <bits/stdc++.h> using namespace std; static int a[5005]; void solve(int n) { a[1] = 0; a[2] = query(1, 2); for(int i = 3; i <= n; i++) { int x1 = a[i - 1] - a[i - 2]; int x2 = query(i - 1, i); int x3 = query(i - 2, i); int sign = (x1 > 0 ? 1 : -1); x1 = abs(x1); if(x1 + x2 == x3) { a[i] = a[i - 1] + x2 * sign; } else { a[i] = a[i - 1] - x2 * sign; } } int mxid = 1, mnid = 1; for(int i = 2; i <= n; i++) { if(a[i] > a[mxid]) mxid = i; if(a[i] < a[mnid]) mnid = i; } if(mxid < mnid) { for(int i = 1; i <= n; i++) a[i] = -a[i]; swap(mnid, mxid); } int ext = 1 - a[mnid]; for(int i = 1; i <= n; i++) { answer(i, a[i] + ext); } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...