Submission #57916

#TimeUsernameProblemLanguageResultExecution timeMemory
57916paulicaXylophone (JOI18_xylophone)C++14
100 / 100
119 ms840 KiB
#include "xylophone.h" #include <bits/stdc++.h> using namespace std; void solve(int n) { int a[5010], d[5010]; for (int i = 0; i < n - 1; i++) d[i] = query(i + 1, i + 2); int sign = 1; a[0] = 0; a[1] = d[0]; for (int i = 1; i < n - 1; i++) { if (query(i, i + 2) != (d[i - 1] + d[i])) sign = -sign; a[i + 1] = a[i] + sign * d[i]; } int posMin = 0, posMax = 0; for (int i = 1; i < n; i++) { if (a[i] < a[posMin]) posMin = i; if (a[i] > a[posMax]) posMax = i; } if (posMin > posMax) { for (int i = 1; i < n; i++) a[i] = -a[i]; swap(posMin, posMax); } for (int i = 0; i < n; i++) answer(i + 1, a[i] - a[posMin] + 1); }

Compilation message (stderr)

xylophone.cpp: In function 'void solve(int)':
xylophone.cpp:14:15: warning: 'd[0]' may be used uninitialized in this function [-Wmaybe-uninitialized]
     a[1] = d[0];
            ~~~^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...