제출 #1338688

#제출 시각아이디문제언어결과실행 시간메모리
1338688kantaponzXylophone (JOI18_xylophone)C++20
100 / 100
27 ms452 KiB
#include "xylophone.h"
#include <bits/stdc++.h>
using namespace std;

const int nx = 5005;

static int A[5000];

int d[nx];
int a[nx], b[nx];

void solve(int N) {
	for (int i = 2; i <= N; i++) {
		d[i] = query(i - 1, i);
	}
	a[2] = d[2];
	for (int i = 1; i + 2 <= N; i++) {
		int x = query(i, i + 2);
		if (x == d[i + 1] + d[i + 2]) {
			if (a[i + 1] < 0) {
				a[i + 2] = -d[i + 2];
			} else {
				a[i + 2] = d[i + 2];
			}
		} else {
			if (a[i + 1] < 0) {
				a[i + 2] = d[i + 2];
			} else {
				a[i + 2] = -d[i + 2];
			}
		}
	}
	for (int i = 1; i <= N; i++) b[i] = -a[i];

	a[1] = b[1] = 1;
	for (int i = 2; i <= N; i++) {
		a[i] = a[i - 1] + a[i];
		b[i] = b[i - 1] + b[i];
	}

	int correct = 0;
	
	int mn = 1e9, mx = -1e9, p, q;
	for (int i = 1; i <= N; i++) {
		if (a[i] < mn) {
			mn = a[i];
			p = i;
		}
		if (a[i] > mx) {
			mx = a[i];
			q = i;
		}
	}

	//cout << p << " " << q << endl;

	if (p <= q) {
		for (int i = 1; i <= N; i++) {
			answer(i, a[i] + (1 - mn));
			//cout << a[i] + (1 - mn) << " ";
		}
		return;
	}

	mn = 1e9, mx = -1e9, p = 0, q = 0;

	for (int i = 1; i <= N; i++) {
		if (b[i] < mn) {
			mn = b[i];
			p = i;
		}
		if (b[i] > mx) {
			mx = b[i];
			q = i;
		}
	}

	for (int i = 1; i <= N; i++) {
		answer(i, b[i] + (1 - mn));
		//cout << b[i] + (1 - mn) << " ";
	}
	return;

}


/*
g++ grader.cpp xylophone.cpp -o o

5
2 1 5 3 4

*/
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...