제출 #1217639

#제출 시각아이디문제언어결과실행 시간메모리
1217639MuhammetXylophone (JOI18_xylophone)C++20
47 / 100
24 ms420 KiB
#include "bits/stdc++.h"
#include "xylophone.h"
// #include "grader.cpp"

using namespace std;

void solve(int n) {

	int k = (query (1, n)), l, r;
	for(int i = 2; i <= n; i++) {
		if(query(i, n) != k) {
			l = i-1;
			break;
		}
	}
	for(int i = n-1; i > l; i--) {
		if(query(l, i) != k) {
			r = i+1;
			break;
		}
	}

	vector <int> ans1(n+1, 0);
	ans1[l] = 1;
	if(l > 1) ans1[l-1] = ans1[l] + query(l-1, l);

	for(int i = l-2; i > 0; i--) {
		int x = ans1[i+1], y = ans1[i+2];
		k = query(i, i+2);
		int k1 = query(i, i+1);
		if(x > y) {
			if(k == (x + k1 - y)) ans1[i] = x + k1;
			else ans1[i] = x - k1;
		}
		else {
			if(k == (y - (x - k1))) ans1[i] = x - k1;
			else ans1[i] = x + k1;
		}
	}

	ans1[l+1] = ans1[l] + query(l, l+1);

	for(int i = l+2; i <= n; i++) {
		int x = ans1[i-1], y = ans1[i-2];
		k = query(i-2, i);
		int k1 = query(i-1, i);
		if(x > y) {
			if(k == (x + k1 - y)) ans1[i] = x + k1;
			else ans1[i] = x - k1;
		}
		else {
			if(k == (y - (x - k1))) ans1[i] = x - k1;
			else ans1[i] = x + k1;
		}
	}

	for(int i = 1; i <= n; i++) {
		answer(i, ans1[i]);
	}

}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...