Submission #1015793

#TimeUsernameProblemLanguageResultExecution timeMemory
1015793ivazivaXylophone (JOI18_xylophone)C++17
100 / 100
69 ms956 KiB
#include <bits/stdc++.h> #include "xylophone.h" using namespace std; #define MAXN 5010 int razlike[MAXN]; int ans1[MAXN],ans2[MAXN]; void solve(int N) { for (int i=1;i<N;i++) razlike[i]=query(i,i+1); ans1[1]=0,ans2[1]=0;ans1[2]=razlike[1],ans2[2]=razlike[1]*(-1); for (int i=3;i<=N;i++) { int sol=query(i-2,i); if (sol==razlike[i-2]+razlike[i-1]) { if (ans1[i-2]>ans1[i-1]) ans1[i]=ans1[i-1]-razlike[i-1]; else ans1[i]=ans1[i-1]+razlike[i-1]; if (ans2[i-2]>ans2[i-1]) ans2[i]=ans2[i-1]-razlike[i-1]; else ans2[i]=ans2[i-1]+razlike[i-1]; } else { if (ans1[i-2]>ans1[i-1]) ans1[i]=ans1[i-1]+razlike[i-1]; else ans1[i]=ans1[i-1]-razlike[i-1]; if (ans2[i-2]>ans2[i-1]) ans2[i]=ans2[i-1]+razlike[i-1]; else ans2[i]=ans2[i-1]-razlike[i-1]; } } int mini1=INT_MAX,mini2=INT_MAX; for (int i=1;i<=N;i++) mini1=min(mini1,ans1[i]); for (int i=1;i<=N;i++) mini2=min(mini2,ans2[i]); int dodajemo1=1-mini1,dodajemo2=1-mini2; for (int i=1;i<=N;i++) ans1[i]+=dodajemo1; for (int i=1;i<=N;i++) ans2[i]+=dodajemo2; int maksi1=-INT_MAX,maksi2=-INT_MAX; for (int i=1;i<=N;i++) maksi1=max(maksi1,ans1[i]); for (int i=1;i<=N;i++) maksi2=max(maksi2,ans2[i]); if (maksi1==N) { int poz1,pozN; for (int i=1;i<=N;i++) { if (ans1[i]==1) poz1=i; if (ans1[i]==N) pozN=i; } if (poz1>pozN) { for (int i=1;i<=N;i++) ans1[i]=N-ans1[i]+1; } for (int i=1;i<=N;i++) answer(i,ans1[i]); } else { int poz1,pozN; for (int i=1;i<=N;i++) { if (ans2[i]==1) poz1=i; if (ans2[i]==N) pozN=i; } if (poz1>pozN) { for (int i=1;i<=N;i++) ans2[i]=N-ans2[i]+1; } for (int i=1;i<=N;i++) answer(i,ans2[i]); } };

Compilation message (stderr)

xylophone.cpp: In function 'void solve(int)':
xylophone.cpp:64:9: warning: 'pozN' may be used uninitialized in this function [-Wmaybe-uninitialized]
   64 |         if (poz1>pozN)
      |         ^~
xylophone.cpp:64:9: warning: 'poz1' may be used uninitialized in this function [-Wmaybe-uninitialized]
xylophone.cpp:50:9: warning: 'pozN' may be used uninitialized in this function [-Wmaybe-uninitialized]
   50 |         if (poz1>pozN)
      |         ^~
xylophone.cpp:50:9: warning: 'poz1' 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...