Submission #127480

# Submission time Handle Problem Language Result Execution time Memory
127480 2019-07-09T12:26:05 Z Markomafko972 Xylophone (JOI18_xylophone) C++14
0 / 100
4 ms 504 KB
#include "xylophone.h"
#include <bits/stdc++.h>
using namespace std;
void solve(int n) {
	int t[5002];
	memset(t, 0, sizeof t);
	int q[5002][5];
	memset(q, 0, sizeof q);
	q[0][2] = query(1, 2);
	t[2] = q[0][2];
	
	int e = min(t[1], t[2]);
	for (int i = 3; i <= n; i ++) {
		q[0][i] = query(i-1, i);
		q[1][i] = query(i-2, i);
		if (t[i-2] < t[i-1]) {
			if (q[0][i] == q[1][i] || q[0][i-1] == q[1][i]) t[i] = t[i-1] - q[0][i];
			else t[i] = t[i-1] + q[0][i];
		}
		else {
			if (q[0][i] == q[1][i] || q[0][i-1] == q[1][i]) t[i] = t[i-1] + q[0][i];
			else t[i] = t[i-1] - q[0][i];
		}
		
		e = min(e, t[i]);
	}
	
	int bio[5002];
	for (int i = 1; i <= n; i ++) {
		t[i] -= e-1;
		bio[t[i]] = 1;
	}
	
	int da = 1;
	for (int i = 1; i <= n; i ++) {
		if (bio[i] == 0) {
			da = 0;
			break;
		}
	}
	
	if (da && t[1] < t[n]) {
		for (int i = 1; i <= n; i ++) {
			answer(i, t[i]);
		}
		
		return;
	}
	
	memset(t, 0, sizeof t);
	t[2] = -q[0][2];
	
	e = min(t[1], t[2]);
	for (int i = 3; i <= n; i ++) {
		if (t[i-2] < t[i-1]) {
			if (q[0][i] == q[1][i] || q[0][i-1] == q[1][i]) t[i] = t[i-1] - q[0][i];
			else t[i] = t[i-1] + q[0][i];
		}
		else {
			if (q[0][i] == q[1][i] || q[0][i-1] == q[1][i]) t[i] = t[i-1] + q[0][i];
			else t[i] = t[i-1] - q[0][i];
		}
		
		e = min(e, t[i]);
	}
	
	memset(bio, 0, sizeof bio);
	for (int i = 1; i <= n; i ++) {
		t[i] -= e-1;
		bio[t[i]] = 1;
	}
	
	da = 1;
	/*for (int i = 1; i <= n; i ++) {
		if (bio[i] == 0) {
			da = 0;
			break;
		}
	}*/
	
	if (da) {
		for (int i = 1; i <= n; i ++) {
			answer(i, t[i]);
		}
		
		return;
	}
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 3 ms 376 KB Output is correct
4 Correct 3 ms 504 KB Output is correct
5 Incorrect 4 ms 504 KB Wrong Answer [4]
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 3 ms 376 KB Output is correct
4 Correct 3 ms 504 KB Output is correct
5 Incorrect 4 ms 504 KB Wrong Answer [4]
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 3 ms 376 KB Output is correct
4 Correct 3 ms 504 KB Output is correct
5 Incorrect 4 ms 504 KB Wrong Answer [4]
6 Halted 0 ms 0 KB -