Submission #197502

#TimeUsernameProblemLanguageResultExecution timeMemory
197502handlenameXylophone (JOI18_xylophone)C++17
100 / 100
116 ms512 KiB
#include "xylophone.h" #include <bits/stdc++.h> using namespace std; int n,arr[5001][2]; int queries[5001][2]; void solve(int N){ n=N; for (int j=0;j<2;j++){ int temp; if (queries[2][0]!=0){ temp=queries[2][0]; } else { temp=query(1,2); queries[2][0]=temp; } if (j==0) arr[2][j]=arr[1][j]+temp; else arr[2][j]=arr[1][j]-temp; for (int i=3;i<=n;i++){ int one; int two; if (queries[i][0]!=0){ one=queries[i][0]; two=queries[i][1]; } else { one=query(i-1,i); two=query(i-2,i); queries[i][0]=one; queries[i][1]=two; } int diff=abs(arr[i-1][j]-arr[i-2][j]); if (arr[i-1][j]>arr[i-2][j]){ if (one+diff==two){ arr[i][j]=arr[i-1][j]+one; } else arr[i][j]=arr[i-1][j]-one; } else { if (one+diff==two){ arr[i][j]=arr[i-1][j]-one; } else arr[i][j]=arr[i-1][j]+one; } } bool works=true; int mini=1e9,lpos,rpos; for (int i=1;i<=n;i++) mini=min(mini,arr[i][j]); for (int i=1;i<=n;i++){ arr[i][j]+=(1-mini); if (arr[i][j]<1 || arr[i][j]>n) works=false; if (arr[i][j]==1) lpos=i; if (arr[i][j]==n) rpos=i; } if (lpos>rpos) works=false; if (works){ for (int i=1;i<=n;i++) answer(i,arr[i][j]); } } }

Compilation message (stderr)

xylophone.cpp: In function 'void solve(int)':
xylophone.cpp:55:9: warning: 'rpos' may be used uninitialized in this function [-Wmaybe-uninitialized]
         if (lpos>rpos) works=false;
         ^~
xylophone.cpp:55:9: warning: 'lpos' 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...