제출 #756336

#제출 시각아이디문제언어결과실행 시간메모리
756336PiokemonXylophone (JOI18_xylophone)C++17
100 / 100
129 ms432 KiB
#include "xylophone.h" #include <bits/stdc++.h> using namespace std; typedef long long int ll; int nast[5009]; int trzy[5009]; bool mniej[5009]; // czy mniejszy od nastepnego int rozn[5009]; void solve(int N) { for (int x=1;x<=N-1;x++){ nast[x] = query(x,x+1); } for (int x=1;x<=N-2;x++){ trzy[x] = query(x,x+2); } mniej[1] = 0; // a1 > a2 for (int x=2;x<N;x++){ if (nast[x-1] + nast[x] == trzy[x-1]) mniej[x] = mniej[x-1]; else mniej[x] = 1-mniej[x-1]; } int mini=0; rozn[1] = 0; for (int x=1;x<N;x++){ if (mniej[x]) rozn[x+1] = rozn[x] + nast[x]; else rozn[x+1] = rozn[x] - nast[x]; mini = min(mini,rozn[x+1]); } int rev=0; for (int x=1;x<=N;x++){ if (-mini + 1 + rozn[x] == 1) break; if (-mini + 1 + rozn[x] == N){ rev = 1; break; } } int pocz = -mini + 1; //for (int x=1;x<=N;x++) cout << rozn[x] << ' '; //cout << '\n'; for (int x=1;x<=N;x++){ if (rev) answer(x,N + 1 - (pocz+rozn[x])); else answer(x,pocz+rozn[x]); } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...