Submission #477584

# Submission time Handle Problem Language Result Execution time Memory
477584 2021-10-02T18:21:26 Z izanbf Xylophone (JOI18_xylophone) C++14
100 / 100
126 ms 320 KB
#include "xylophone.h"
#include <vector>
using namespace std;

using vi = vector<int>;

static int A[5000];

void solution(int N, const vi& q2, const vi& q3, bool last_initial_assumption) {
	// last : el último era mayor que el de su izquierda?
	bool last = last_initial_assumption;
	vi s(N+1);
	
	if (last) 
		s[2] = s[1] + q2[1];
	else 
		s[2] = s[1] - q2[1];

	for (int i = 1; i <= N-2; ++i) {
		if (q3[i] != q2[i] + q2[i+1]) 
			last = not last;

		if (last) 
			s[i+2] = s[i+1] + q2[i+1];
		else
			s[i+2] = s[i+1] - q2[i+1];
	}

	int min_pos = 1;
	int max_pos = 1;
	for (int i = 2; i <= N; ++i) {
		if (s[i] < s[min_pos]) min_pos = i;
		if (s[i] > s[max_pos]) max_pos = i;
	}

	if (min_pos < max_pos) { // requisito solucion válida
		for (int i = 1; i <= N; ++i) {
			answer(i, s[i] - s[min_pos] + 1);
			// con s[i] - s[min_pos] + 1 desplazamos todos los valores
			// para que estén entre 1 y N
		} 
	}
}

void solve(int N) {
	vi q2(N+1), q3(N+1);
	for (int i = 1; i <= N-1; ++i) q2[i] = query(i, i+1);
	for (int i = 1; i <= N-2; ++i) q3[i] = query(i, i+2);
	solution(N, q2, q3, false);
	solution(N, q2, q3, true);
}

Compilation message

xylophone.cpp:7:12: warning: 'A' defined but not used [-Wunused-variable]
    7 | static int A[5000];
      |            ^
# Verdict Execution time Memory Grader output
1 Correct 1 ms 200 KB Output is correct
2 Correct 0 ms 200 KB Output is correct
3 Correct 1 ms 200 KB Output is correct
4 Correct 2 ms 200 KB Output is correct
5 Correct 3 ms 200 KB Output is correct
6 Correct 2 ms 200 KB Output is correct
7 Correct 2 ms 200 KB Output is correct
8 Correct 2 ms 256 KB Output is correct
9 Correct 2 ms 200 KB Output is correct
10 Correct 1 ms 200 KB Output is correct
11 Correct 2 ms 200 KB Output is correct
12 Correct 2 ms 200 KB Output is correct
13 Correct 2 ms 200 KB Output is correct
14 Correct 1 ms 200 KB Output is correct
15 Correct 2 ms 200 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 200 KB Output is correct
2 Correct 0 ms 200 KB Output is correct
3 Correct 1 ms 200 KB Output is correct
4 Correct 2 ms 200 KB Output is correct
5 Correct 3 ms 200 KB Output is correct
6 Correct 2 ms 200 KB Output is correct
7 Correct 2 ms 200 KB Output is correct
8 Correct 2 ms 256 KB Output is correct
9 Correct 2 ms 200 KB Output is correct
10 Correct 1 ms 200 KB Output is correct
11 Correct 2 ms 200 KB Output is correct
12 Correct 2 ms 200 KB Output is correct
13 Correct 2 ms 200 KB Output is correct
14 Correct 1 ms 200 KB Output is correct
15 Correct 2 ms 200 KB Output is correct
16 Correct 5 ms 280 KB Output is correct
17 Correct 8 ms 200 KB Output is correct
18 Correct 14 ms 200 KB Output is correct
19 Correct 16 ms 200 KB Output is correct
20 Correct 23 ms 280 KB Output is correct
21 Correct 21 ms 200 KB Output is correct
22 Correct 16 ms 200 KB Output is correct
23 Correct 17 ms 272 KB Output is correct
24 Correct 20 ms 200 KB Output is correct
25 Correct 22 ms 280 KB Output is correct
26 Correct 17 ms 264 KB Output is correct
27 Correct 18 ms 320 KB Output is correct
28 Correct 16 ms 200 KB Output is correct
29 Correct 18 ms 200 KB Output is correct
30 Correct 16 ms 200 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 200 KB Output is correct
2 Correct 0 ms 200 KB Output is correct
3 Correct 1 ms 200 KB Output is correct
4 Correct 2 ms 200 KB Output is correct
5 Correct 3 ms 200 KB Output is correct
6 Correct 2 ms 200 KB Output is correct
7 Correct 2 ms 200 KB Output is correct
8 Correct 2 ms 256 KB Output is correct
9 Correct 2 ms 200 KB Output is correct
10 Correct 1 ms 200 KB Output is correct
11 Correct 2 ms 200 KB Output is correct
12 Correct 2 ms 200 KB Output is correct
13 Correct 2 ms 200 KB Output is correct
14 Correct 1 ms 200 KB Output is correct
15 Correct 2 ms 200 KB Output is correct
16 Correct 5 ms 280 KB Output is correct
17 Correct 8 ms 200 KB Output is correct
18 Correct 14 ms 200 KB Output is correct
19 Correct 16 ms 200 KB Output is correct
20 Correct 23 ms 280 KB Output is correct
21 Correct 21 ms 200 KB Output is correct
22 Correct 16 ms 200 KB Output is correct
23 Correct 17 ms 272 KB Output is correct
24 Correct 20 ms 200 KB Output is correct
25 Correct 22 ms 280 KB Output is correct
26 Correct 17 ms 264 KB Output is correct
27 Correct 18 ms 320 KB Output is correct
28 Correct 16 ms 200 KB Output is correct
29 Correct 18 ms 200 KB Output is correct
30 Correct 16 ms 200 KB Output is correct
31 Correct 46 ms 276 KB Output is correct
32 Correct 50 ms 284 KB Output is correct
33 Correct 85 ms 292 KB Output is correct
34 Correct 73 ms 308 KB Output is correct
35 Correct 111 ms 300 KB Output is correct
36 Correct 81 ms 316 KB Output is correct
37 Correct 104 ms 312 KB Output is correct
38 Correct 83 ms 320 KB Output is correct
39 Correct 82 ms 320 KB Output is correct
40 Correct 97 ms 320 KB Output is correct
41 Correct 83 ms 312 KB Output is correct
42 Correct 76 ms 300 KB Output is correct
43 Correct 109 ms 300 KB Output is correct
44 Correct 108 ms 296 KB Output is correct
45 Correct 87 ms 308 KB Output is correct
46 Correct 103 ms 300 KB Output is correct
47 Correct 114 ms 300 KB Output is correct
48 Correct 50 ms 312 KB Output is correct
49 Correct 107 ms 304 KB Output is correct
50 Correct 103 ms 296 KB Output is correct
51 Correct 111 ms 320 KB Output is correct
52 Correct 126 ms 300 KB Output is correct
53 Correct 101 ms 312 KB Output is correct
54 Correct 86 ms 320 KB Output is correct
55 Correct 68 ms 316 KB Output is correct
56 Correct 74 ms 304 KB Output is correct
57 Correct 110 ms 296 KB Output is correct
58 Correct 94 ms 300 KB Output is correct
59 Correct 101 ms 312 KB Output is correct
60 Correct 82 ms 296 KB Output is correct