Submission #996009

# Submission time Handle Problem Language Result Execution time Memory
996009 2024-06-10T07:14:18 Z BuzzyBeez Xylophone (JOI18_xylophone) C++17
0 / 100
2 ms 444 KB
#include "xylophone.h"
#include <bits/stdc++.h>
using namespace std;

int d[5008][3];
int a[5008];
bool mark[5008];

bool check(int n) {
	fill(mark + 1, mark + n + 1, 0);
	for (int i = 1; i <= n; ++i)
		if (a[i] <= 0 || a[i] > n) return 0;
		else mark[a[i]] = 1;
	for (int i = 1; i <= n; ++i) if (!mark[i]) return 0;
	return 1;
}

void deduce(int n) {
	for (int i = 3; i <= n; ++i) {
		if (a[i - 2] > a[i - 1]) {
			if (a[i - 2] - a[i - 1] + d[i][1] == d[i][2]) a[i] = a[i - 1] - d[i][1];
			else a[i] = a[i - 1] + d[i][1];
		}
		else {
			if (a[i - 1] - a[i - 2] + d[i][1] == d[i][2]) a[i] = a[i - 1] + d[i][1];
			else a[i] = a[i - 1] - d[i][1];
		}
	}
}

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

void solve(int n) {
	for (int i = 3; i <= n; ++i) d[i][1] = query(i - 1, i), d[i][2] = query(i - 2, i);
	int d12 = query(1, 2);
	for (a[1] = 1; a[1] <= n; ++a[1]) {
		a[2] = a[1] + d12; deduce(n);
		if (check(n)) {return_answer(n); return;}
		a[2] = a[1] - d12; deduce(n);
		if (check(n)) {return_answer(n); return;}		
	}
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 0 ms 444 KB Output is correct
4 Correct 2 ms 344 KB Output is correct
5 Incorrect 1 ms 344 KB Wrong Answer [7]
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 0 ms 444 KB Output is correct
4 Correct 2 ms 344 KB Output is correct
5 Incorrect 1 ms 344 KB Wrong Answer [7]
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 0 ms 444 KB Output is correct
4 Correct 2 ms 344 KB Output is correct
5 Incorrect 1 ms 344 KB Wrong Answer [7]
6 Halted 0 ms 0 KB -