Submission #516075

#TimeUsernameProblemLanguageResultExecution timeMemory
516075lovrotXylophone (JOI18_xylophone)C++11
0 / 100
0 ms288 KiB
#include <bits/stdc++.h> #include "xylophone.h" using namespace std; int rj[10000]; void solve(int n){ int p; for (int i=n;i>0;i--){ int odg = query(1, i); if (odg<n-1){ rj[i+1]=n; p=i+1; break; } } if (n!=p){ int odg = query(p, p + 1); rj[p+1]=n-odg; } if (1!=p){ int odg = query(p, p - 1); rj[p-1]=n-odg; } for (int i=p+2;i<n+1;i++){ int odg1 = query(i - 1, i); //cout<<"query("<<i-2<<", "<<i<<")"<<endl; int odg2 = query(i - 2, i); if (rj[i-1]>rj[i-2]){ if (odg2==rj[i-1]-rj[i-2]+odg1){ rj[i]=rj[i-1]+odg1; } else { rj[i]=rj[i-1]-odg1; } } else { if (odg2==rj[i-2]-rj[i-1]+odg1){ rj[i]=rj[i-1]-odg1; } else { rj[i]=rj[i-1]+odg1; } } } for (int i=p-2;i>0;i--){ int odg1 = query(i + 1, i); int odg2 = query(i + 2, i); if (rj[i+1]>rj[i+2]){ if (odg2==rj[i+1]-rj[i+2]+odg1){ rj[i]=rj[i+1]+odg1; } else { rj[i]=rj[i+1]-odg1; } } else { if (odg2==rj[i+2]-rj[i+1]+odg1){ rj[i]=rj[i+1]-odg1; } else { rj[i]=rj[i+1]+odg1; } } } for (int i=1;i<n+1;i++){ answer(i, rj[i]); } return; }

Compilation message (stderr)

xylophone.cpp: In function 'void solve(int)':
xylophone.cpp:24:18: warning: 'p' may be used uninitialized in this function [-Wmaybe-uninitialized]
   24 |   int odg = query(p, p - 1);
      |             ~~~~~^~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...