제출 #542444

#제출 시각아이디문제언어결과실행 시간메모리
542444status_codingXylophone (JOI18_xylophone)C++14
0 / 100
1 ms208 KiB
#include "xylophone.h" #include <bits/stdc++.h> using namespace std; int n; int a[5005]; map<int, int> fr; int findN() { int st=2, dr=n, mij, last; while(st <= dr) { mij = (st+dr)/2; //cout<<1<<' '<<mij<<'\n'; if(query(1, mij) == n-1) { last=mij; dr=mij-1; } else st=mij+1; } return last; } bool bad(int x) { if(x > n) return true; if(x < 0) return true; if(fr[x]) return true; return false; } void solve(int N) { n=N; int p = findN(); a[p] = n; fr[n]=1; int mini=n; for(int i=p-1;i>=1;i--) { int dif = query(i, i+1); int x1 = a[i+1] - dif; int x2 = a[i+1] + dif; if(bad(x1)) a[i]=x2; else if(bad(x2)) a[i]=x1; else { int nQ = query(i, p); if(nQ > n - mini) a[i]=n-nQ; else a[i]=x2; } mini=min(mini, a[i]); fr[ a[i] ] =1; } mini=n; for(int i=p+1;i<=n;i++) { int dif = query(i-1, i); int x1 = a[i-1] - dif; int x2 = a[i-1] + dif; if(bad(x1)) a[i]=x2; else if(bad(x2)) a[i]=x1; else { int nQ = query(p, i); if(nQ > n - mini) a[i]=n-nQ; else a[i]=x2; } mini=min(mini, a[i]); fr[ a[i] ] =1; } /* for(int i=1;i<=n;i++) cout<<a[i]<<' '; */ for(int i=1;i<=n;i++) answer(i, a[i]); }

컴파일 시 표준 에러 (stderr) 메시지

xylophone.cpp: In function 'int findN()':
xylophone.cpp:29:12: warning: 'last' may be used uninitialized in this function [-Wmaybe-uninitialized]
   29 |     return last;
      |            ^~~~
xylophone.cpp: In function 'void solve(int)':
xylophone.cpp:54:13: warning: 'last' may be used uninitialized in this function [-Wmaybe-uninitialized]
   54 |     for(int i=p-1;i>=1;i--)
      |             ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...