제출 #698604

#제출 시각아이디문제언어결과실행 시간메모리
698604vjudge1Xylophone (JOI18_xylophone)C++17
100 / 100
121 ms336 KiB
#include "xylophone.h" #include <bits/stdc++.h> using namespace std; static int A[5005]; void solve(int N) { int nxt[N], tri[N-1]; for(int i = 1; i < N; ++i) { nxt[i] = query(i, i + 1); } for(int i = 1; i < N - 1; ++i) { tri[i] = query(i, i + 2); } bool turn[N + 5]; for(int i = 2; i < N; ++i) { turn[i] = tri[i - 1] != nxt[i - 1] + nxt[i]; } // assume a[1] == 1 and go up // shift everything later on // if pos 1 > pos N then make everything A[i] = N - A[i] A[1] = 1; bool up = 1; for(int i = 2; i <= N; ++i) { if(up) A[i] = A[i - 1] + nxt[i - 1]; else A[i] = A[i - 1] - nxt[i - 1]; if(i != N) up ^= turn[i]; } int min_elem = 1e9, idx; for(int i = 1; i <= N; ++i) { if(A[i] < min_elem) idx = i, min_elem = A[i]; } for(int i = 1; i <= N; ++i) A[i] += 1 - min_elem; int onepos, npos; for(int i = 1; i <= N; ++i) { if(A[i] == 1) onepos = i; if(A[i] == N) npos = i; } if(onepos > npos) { for(int i = 1; i <= N; ++i) A[i] = N + 1 - A[i]; } //for(int i = 1; i <= N; ++i) // cout << A[i] << " "; //cout << endl; for(int i = 1; i <= N; ++i) answer(i, A[i]); }

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

xylophone.cpp: In function 'void solve(int)':
xylophone.cpp:31:22: warning: variable 'idx' set but not used [-Wunused-but-set-variable]
   31 |  int min_elem = 1e9, idx;
      |                      ^~~
xylophone.cpp:45:2: warning: 'onepos' may be used uninitialized in this function [-Wmaybe-uninitialized]
   45 |  if(onepos > npos) {
      |  ^~
xylophone.cpp:45:2: warning: 'npos' 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...