Submission #478989

#TimeUsernameProblemLanguageResultExecution timeMemory
478989ponytailXylophone (JOI18_xylophone)C++17
100 / 100
135 ms448 KiB
//SUBMIT #include <bits/stdc++.h> #include "xylophone.h" using namespace std; static int A[16384]; void solve(int N) { if(N == 2) { answer(1, 1); answer(2, 2); return; } int P[N+1]; int delta[N+1]; int one[N+1], two[N+1]; for(int i = 1; i < N; i++) { one[i] = query(i, i+1); } for(int i=1; i<N-1; i++) { two[i] = query(i, i+2); } if(one[1] + one[2] == two[1]) delta[1] = one[1], delta[2] = one[2]; else delta[1] = one[1], delta[2] = -one[2]; for(int i=3; i<N; i++) { if(one[i-1] + one[i] == two[i-1]) delta[i] = (delta[i-1] > 0 ? 1 : -1) * one[i]; else delta[i] = (delta[i-1] > 0 ? -1 : 1) * one[i]; } int mini, maxi, cur; mini = 0, maxi = 0, cur = 0; for(int i=1; i<N; i++) { cur += delta[i]; mini = min(mini, cur); maxi = max(maxi, cur); } cur = 0; int pos[N+1]; for(int i=2; i<=N; i++) { cur += delta[i-1]; P[i] = cur - mini + 1; pos[P[i]] = i; } P[1] = -mini + 1; pos[-mini + 1] = 1; if(pos[1] > pos[N]) { for(int i=1; i<N; i++) delta[i] *= -1; mini = 0, maxi = 0, cur = 0; for(int i=1; i<N; i++) { cur += delta[i]; mini = min(mini, cur); maxi = max(maxi, cur); } cur = 0; for(int i=2; i<=N; i++) { cur += delta[i-1]; P[i] = cur - mini + 1; } P[1] = -mini + 1; } for(int i=1; i<=N; i++) { answer(i, P[i]); } } //END SUBMIT

Compilation message (stderr)

xylophone.cpp:9:12: warning: 'A' defined but not used [-Wunused-variable]
    9 | static int A[16384];
      |            ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...