Submission #577963

#TimeUsernameProblemLanguageResultExecution timeMemory
577963JomnoiXylophone (JOI18_xylophone)C++17
100 / 100
114 ms472 KiB
#include <bits/stdc++.h> #include "xylophone.h" using namespace std; static int A[5000]; const int MAX_N = 5005; const int INF = 1e9 + 7; int arr[MAX_N]; int q1[MAX_N], q2[MAX_N]; void solve(int N) { for(int i = 1; i <= N; i++) { if(i - 1 >= 1) { q1[i] = query(i - 1, i); } if(i - 2 >= 1) { q2[i] = query(i - 2, i); } } arr[1] = 0; arr[2] = q1[2]; for(int i = 3; i <= N; i++) { if(q1[i] + q1[i - 1] == q2[i]) { if(arr[i - 2] < arr[i - 1]) { arr[i] = arr[i - 1] + q1[i]; } else { arr[i] = arr[i - 1] - q1[i]; } } else { if(arr[i - 2] < arr[i - 1]) { arr[i] = arr[i - 1] - q1[i]; } else { arr[i] = arr[i - 1] + q1[i]; } } } int min_value = INF; for(int i = 1; i <= N; i++) { min_value = min(min_value, arr[i]); } for(int i = 1; i <= N; i++) { arr[i] -= min_value - 1; } int idx_min, idx_max; for(int i = 1; i <= N; i++) { if(arr[i] == 1) { idx_min = i; } else if(arr[i] == N) { idx_max = i; } } if(idx_max < idx_min) { for(int i = 1; i <= N; i++) { arr[i] = N - arr[i] + 1; } } for(int i = 1; i <= N; i++) { answer(i, arr[i]); } }

Compilation message (stderr)

xylophone.cpp:5:12: warning: 'A' defined but not used [-Wunused-variable]
    5 | static int A[5000];
      |            ^
xylophone.cpp: In function 'void solve(int)':
xylophone.cpp:62:2: warning: 'idx_max' may be used uninitialized in this function [-Wmaybe-uninitialized]
   62 |  if(idx_max < idx_min) {
      |  ^~
xylophone.cpp:62:2: warning: 'idx_min' may be used uninitialized in this function [-Wmaybe-uninitialized]
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...