제출 #115545

#제출 시각아이디문제언어결과실행 시간메모리
115545dndhkXylophone (JOI18_xylophone)C++14
100 / 100
111 ms512 KiB
#include "xylophone.h" #include <algorithm> #include <iostream> using namespace std; int arr[5001]; int zero(int x){ return (x>0)?x:-x; } void solve(int N) { arr[1] = 1; arr[2] = query(1, 2) + 1; int mn = 1; for(int i=3; i<=N; i++){ int t = query(i-2, i); if(t==zero(arr[i-1]- arr[i-2])){ int k = query(i-1, i); if(arr[i-1]>arr[i-2]){ arr[i] = arr[i-1] - k; }else{ arr[i]= arr[i-1] + k; } }else{ int k = query(i-1, i); if(arr[i-1]>arr[i-2]){ if(k==t){ arr[i] = arr[i-1] - k; }else{ arr[i] = arr[i-1] + k; } }else{ if(k==t){ arr[i] = arr[i-1] + k; }else{ arr[i] = arr[i-1] - k; } } } mn = min(arr[i], mn); } //for(int i=1; i<=N; i++){ // cout<<i<<" "<<arr[i]<<endl; //} int idx1 = 1, idx2 = 1; for(int i=1; i<=N; i++){ arr[i] = arr[i] - mn + 1; if(arr[i]>arr[idx1]){ idx1 = i; }else if(arr[i]<arr[idx2]){ idx2 = i; } } if(idx1<idx2){ mn = arr[1]; for(int i=1; i<=N; i++){ arr[i] = arr[1]*2-arr[i]; mn = min(arr[i], mn); } for(int i=1; i<=N; i++){ arr[i] = arr[i] - mn + 1; } } //for(int i=1; i<=N; i++){ // cout<<i<<" "<<arr[i]<<endl; //} for(int i=1; i<=N; i++){ answer(i, arr[i]); } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...