제출 #1150689

#제출 시각아이디문제언어결과실행 시간메모리
1150689minggaXylophone (JOI18_xylophone)C++20
컴파일 에러
0 ms0 KiB
#include "xylophone.h"

static int a[5005];

void solve(int n) {
	a[1] = 0;
	a[2] = query(1, 2);
	int mxid = 2, mnid = 1;
	for(int i = 3; i <= n; i++) {
		int x1 = a[i - 1] - a[i - 2];
		int x2 = query(i - 1, i);
		int x3 = query(i - 2, i);
		int sign = (x1 > 0 ? 1 : -1);
		if(x1 + x2 == x3) {
			a[i] = x1 + x2 * sign; 
		} else {
			a[i] = x1 - x2 * sign;
		}
		if(a[i] > a[mxid]) mxid = i;
		if(a[i] < a[mnid]) mnid = i;
	}
	if(mxid < mnid) {
		for(int i = 1; i <= n; i++) a[i] = -a[i];
		swap(mnid, mxid);
	}
	int ext = 1 - a[mnid];
	for(int i = 1; i <= n; i++) {
		answer(i, a[i] + ext);
	}
}

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

xylophone.cpp: In function 'void solve(int)':
xylophone.cpp:24:17: error: 'swap' was not declared in this scope
   24 |                 swap(mnid, mxid);
      |                 ^~~~