제출 #996113

#제출 시각아이디문제언어결과실행 시간메모리
996113vjudge1Xylophone (JOI18_xylophone)C++17
100 / 100
261 ms97372 KiB
#include "xylophone.h" #include<bits/stdc++.h> using namespace std; static int a[5005]; static int d[5005][5005]; void solve(int n) { int dis = query(1, 2); for(int i=3; i<=n; i++) { d[i - 2][i] = query(i - 2, i); d[i - 1][i] = query(i - 1, i); } for(int i=1; i<=n; i++) { a[1] = i; for(int k=-1; k<=1; k+=2) { a[2] = a[1] + k*dis; for(int j=3; j<=n; j++) { int cal = max(a[j - 1], a[j - 2]) - min(a[j - 1], a[j - 2]); if(d[j - 2][j] == cal) { if(a[j - 1] > a[j - 2]) a[j] = a[j - 1] - d[j - 1][j]; else a[j] = a[j - 1] + d[j - 1][j]; } else { if(a[j - 1] + d[j - 1][j] - min(a[j - 2], a[j - 1]) == d[j - 2][j]) a[j] = a[j - 1] + d[j - 1][j]; if(max(a[j - 2], a[j - 1]) - (a[j - 1] - d[j - 1][j]) == d[j - 2][j]) a[j] = a[j - 1] - d[j - 1][j]; } } int mi = 1e9, mx = -1e9; long long sum = 0; for(int j=1; j<=n; j++) { mi = min(mi, a[j]); mx = max(mx, a[j]); sum += a[j]; } if(mi == 1 && mx == n && sum == 1LL*n*(n + 1)/2) { int p1, pn; for(int j=1; j<=n; j++) { if(a[j] == 1) p1 = j; if(a[j] == n) pn = j; } if(p1 < pn) { for(int j=1; j<=n; j++) answer(j, a[j]); return; } } } } }

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

xylophone.cpp: In function 'void solve(int)':
xylophone.cpp:43:17: warning: 'pn' may be used uninitialized in this function [-Wmaybe-uninitialized]
   43 |                 if(p1 < pn) {
      |                 ^~
xylophone.cpp:43:17: warning: 'p1' 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...