Submission #851436

#TimeUsernameProblemLanguageResultExecution timeMemory
851436AndreiXylophone (JOI18_xylophone)C++17
100 / 100
65 ms1464 KiB
#include <bits/stdc++.h> using namespace std; int a[5005]; int b[5005]; int diff1[5005]; int diff2[5005]; bool same[5005]; bool bigger[5005]; int query(int s,int t); void answer(int i,int v); void solve(int n) { if(n==2) { answer(1,1); answer(2,2); return; } for(int i=1; i<n; i++) diff1[i]=query(i,i+1); for(int i=1; i<n-1; i++) diff2[i]=query(i,i+2); for(int i=1; i<n-1; i++) { if(diff2[i]==diff1[i]+diff1[i+1]) same[i]=1; else same[i]=0; } int sign=1; a[1]=0; for(int i=1; i<n; i++) { a[i+1]=a[i]+sign*diff1[i]; if(i+1<n && same[i]==0) sign*=-1; } sign=-1; b[1]=0; for(int i=1; i<n; i++) { b[i+1]=b[i]+sign*diff1[i]; if(i+1<n && same[i]==0) sign*=-1; } /* for(int i=1; i<=n; i++) cout<<A[i]<<" "; cout<<"\n"; for(int i=1; i<=n; i++) cout<<B[i]<<" "; cout<<"\n"; */ int minA=n; for(int i=1; i<=n; i++) minA=min(minA,a[i]); int minB=n; for(int i=1; i<=n; i++) minB=min(minB,b[i]); int pminA,pminB; for(int i=1; i<=n; i++) { if(a[i]==minA) pminA=i; if(b[i]==minB) pminB=i; } if(pminB<pminA) { for(int i=1; i<=n; i++) swap(a[i],b[i]); swap(minA,minB); } for(int i=1; i<=n; i++) answer(i,a[i]-minA+1); }

Compilation message (stderr)

xylophone.cpp: In function 'void solve(int)':
xylophone.cpp:84:5: warning: 'pminB' may be used uninitialized in this function [-Wmaybe-uninitialized]
   84 |     if(pminB<pminA)
      |     ^~
xylophone.cpp:84:5: warning: 'pminA' 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...