Submission #565699

# Submission time Handle Problem Language Result Execution time Memory
565699 2022-05-21T09:38:32 Z haxorman Xylophone (JOI18_xylophone) C++14
0 / 100
1 ms 208 KB
#include "xylophone.h"
#include <bits/stdc++.h>
using namespace std;

int arr[5001];

void solve(int n) {
	map<int,int> pos;
	for (int i = 2; i <= n; ++i) {
		int dif = query(i, n);

		if (dif < n - 1) {
			arr[i - 1] = 1;
			pos[1] = i - 1;
			break;
		}
	}

	for (int i = pos[1]; i < n; ++i) {
		int dif = query(i, i + 1);

		int big = arr[i] + dif;
		int small = arr[i] - dif;

		if (pos.count(small) || small < 1) {
			arr[i + 1] = big;
			pos[big] = i + 1;
		}
		else if (pos.count(big) || big > n) {
			arr[i + 1] = small;
			pos[small] = i + 1;
		}
		else {
			int new_dif = query(i - 1, i + 1);

			if (arr[i - 1] > arr[i]) {
				if (dif < new_dif) {
					arr[i + 1] = big;
					pos[big] = i + 1;
				}
				else {
					arr[i + 1] = small;
					pos[small] = i + 1;
				}
			}
			else {
				if (dif < new_dif) {
					arr[i + 1] = small;
					pos[small] = i + 1;
				}
				else {
					arr[i + 1] = big;
					pos[big] = i + 1;
				}
			}
		}
	}

	for (int i = pos[1]; i > 1; --i) {
		int dif = query(i - 1, i);
		
		int big = arr[i] + dif;
		int small = arr[i] - dif;

		if (pos.count(small) || small < 1) {
			arr[i - 1] = big;
			pos[big] = i + 1;
		}
		else if (pos.count(big) || big > n) {
			arr[i - 1] = small;
			pos[small] = i + 1;
		}
		else {
			int new_dif = query(i - 1, i + 1);

			if (arr[i + 1] > arr[i]) {
				if (dif < new_dif) {
					arr[i - 1] = big;
					pos[big] = i + 1;
				}
				else {
					arr[i - 1] = small;
					pos[small] = i + 1;
				}
			}
			else {
				if (dif > new_dif) {
					arr[i - 1] = small;
					pos[small] = i + 1;
				}
				else {
					arr[i - 1] = big;
					pos[big] = i + 1;
				}
			}
		}
	}

	for (int i = 1; i <= n; ++i) {
		//cout << arr[i] << ' ';
		answer(i, arr[i]);
	}
	//cout << "\n";
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 208 KB Output is correct
2 Correct 0 ms 208 KB Output is correct
3 Incorrect 1 ms 208 KB Wrong Answer [7]
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 208 KB Output is correct
2 Correct 0 ms 208 KB Output is correct
3 Incorrect 1 ms 208 KB Wrong Answer [7]
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 208 KB Output is correct
2 Correct 0 ms 208 KB Output is correct
3 Incorrect 1 ms 208 KB Wrong Answer [7]
4 Halted 0 ms 0 KB -