제출 #363278

#제출 시각아이디문제언어결과실행 시간메모리
363278teewarXylophone (JOI18_xylophone)C++14
컴파일 에러
0 ms0 KiB
#include "xylophone.h" void solve(int n) { int a[n + 1]; int l = 1, r = n; while(r - l > 1) { int m = (l + r) / 2; if(query(1, m) >= n - 1) { r = m; } else { l = m; } } int mxid = r; a[mxid] = n; if(mxid > 1) { a[mxid - 1] = a[mxid] - query(mxid - 1, mxid); } if(mxid + 1 <= n) { a[mxid + 1] = a[mxid] - query(mxid, mxid + 1); } for(int i = mxid + 2; i <= n; ++i) { int p = query(i - 1, i); int val1 = a[i - 1] - p; int val2 = a[i - 1] + p; if(val1 < 1) { a[i] = val2; continue; } if(val2 >= n) { a[i] = val1; continue; } int t = query(i - 2, i); if(abs(a[i - 1] - a[i - 2]) + p == t) { if(a[i - 2] < a[i - 1]) { a[i] = val2; } else { a[i] = val1; } } else { if(a[i - 2] < a[i - 1]) { a[i] = val1; } else { a[i] = val2; } } } for(int i = mxid - 2; i >= 1; --i) { int p = query(i, i + 1); int val1 = a[i + 1] - p; int val2 = a[i + 1] + p; if(val1 < 1) { a[i] = val2; continue; } if(val2 >= n) { a[i] = val1; continue; } int t = query(i, i + 2); if(abs(a[i + 1] - a[i + 2]) + p == t) { if(a[i - 1] < a[i - 2]) { a[i] = val1; } else { a[i] = val2; } } else { if(a[i - 1] < a[i - 2]) { a[i] = val2; } else { a[i] = val1; } } } for(int i = 1; i <= n; ++i) { answer(i, a[i]); } }

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

xylophone.cpp: In function 'void solve(int)':
xylophone.cpp:36:12: error: 'abs' was not declared in this scope
   36 |         if(abs(a[i - 1] - a[i - 2]) + p == t) {
      |            ^~~
xylophone.cpp:66:12: error: 'abs' was not declared in this scope
   66 |         if(abs(a[i + 1] - a[i + 2]) + p == t) {
      |            ^~~