답안 #59711

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
59711 2018-07-22T23:48:56 Z MatheusLealV Xylophone (JOI18_xylophone) C++17
100 / 100
224 ms 20980 KB
#include "xylophone.h"
#include <bits/stdc++.h>
using namespace std;

int ans[5005][2], L[5005], R[5005];

int save[5005][5005];

int n,pos1, qtd[5005][2];

int Q(int a, int b)
{
	if(a >= b) return 0;

	if(save[a][b] != 0) return save[a][b];

	return save[a][b] = query(a, b);
}

int usado[5005];

void solve(int N)
{
	n = N;

	int subindo = 1, subindo2 = -1;

	ans[2][1] = -Q(1, 2);

	ans[2][0] = Q(1, 2);

	for(int p = 3; p <= n; p++)
	{
		int A = Q(p - 2, p), B = Q(p - 2, p - 1), C = Q(p - 1, p);

		if(A == B + C)
		{
			ans[p][0] = ans[p - 1][0] + C*subindo;

			ans[p][1] = ans[p - 1][1] + C*subindo2;
		}

		else
		{
			subindo *= -1;

			subindo2 *= -1;

			ans[p][0] = ans[p - 1][0] + C*subindo;

			ans[p][1] = ans[p - 1][1] + C*subindo2;
		}
	}


	for(int i = 1; i <= n; i++)
	{

		int P1 = -1, ok = 1;

		memset(usado, 0, sizeof usado);

		for(int j = 1; j <= n; j++)
		{
			if(i + ans[j][0] > n or i + ans[j][0] <= 0)
			{
				ok = 0;

				break;
			}

			if(i + ans[j][0] == 1) P1 = 1;

			if(i + ans[j][0] == n and P1 == -1) ok = 0;

			usado[i + ans[j][0]] = 1;
		}

		for(int j = 1; j <= n; j++)
			if(!usado[j]) ok = 0;

		if(ok)
		{
			for(int j = 1; j <= n; j++)
				answer(j, ans[j][0] + i);
			break;
		}

		memset(usado, 0, sizeof usado);

		ok = 1;

		P1 = -1;

		for(int j = 1; j <= n; j++)
		{
			if(i + ans[j][1] > n or i + ans[j][1] <= 0)
			{
				ok = 0;

				break;
			}

			if(i + ans[j][1] == 1) P1 = 1;

			if(i + ans[j][1] == n and P1 == -1) ok = 0;

			usado[i + ans[j][1]] = 1;
		}

		for(int j = 1; j <= n; j++)
			if(!usado[j]) ok = 0;

		if(ok)
		{
			for(int j = 1; j <= n; j++)
				answer(j, ans[j][1] + i);
			break;
		}
	}
}

Compilation message

xylophone.cpp: In function 'void solve(int)':
xylophone.cpp:13:2: warning: assuming signed overflow does not occur when assuming that (X - c) > X is always false [-Wstrict-overflow]
  if(a >= b) return 0;
  ^~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 248 KB Output is correct
2 Correct 2 ms 436 KB Output is correct
3 Correct 4 ms 548 KB Output is correct
4 Correct 6 ms 808 KB Output is correct
5 Correct 6 ms 860 KB Output is correct
6 Correct 4 ms 884 KB Output is correct
7 Correct 5 ms 884 KB Output is correct
8 Correct 6 ms 884 KB Output is correct
9 Correct 4 ms 936 KB Output is correct
10 Correct 6 ms 936 KB Output is correct
11 Correct 5 ms 936 KB Output is correct
12 Correct 6 ms 936 KB Output is correct
13 Correct 9 ms 936 KB Output is correct
14 Correct 8 ms 936 KB Output is correct
15 Correct 5 ms 936 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 248 KB Output is correct
2 Correct 2 ms 436 KB Output is correct
3 Correct 4 ms 548 KB Output is correct
4 Correct 6 ms 808 KB Output is correct
5 Correct 6 ms 860 KB Output is correct
6 Correct 4 ms 884 KB Output is correct
7 Correct 5 ms 884 KB Output is correct
8 Correct 6 ms 884 KB Output is correct
9 Correct 4 ms 936 KB Output is correct
10 Correct 6 ms 936 KB Output is correct
11 Correct 5 ms 936 KB Output is correct
12 Correct 6 ms 936 KB Output is correct
13 Correct 9 ms 936 KB Output is correct
14 Correct 8 ms 936 KB Output is correct
15 Correct 5 ms 936 KB Output is correct
16 Correct 16 ms 1444 KB Output is correct
17 Correct 22 ms 2468 KB Output is correct
18 Correct 27 ms 3884 KB Output is correct
19 Correct 36 ms 4648 KB Output is correct
20 Correct 48 ms 4648 KB Output is correct
21 Correct 45 ms 4648 KB Output is correct
22 Correct 40 ms 4648 KB Output is correct
23 Correct 38 ms 4648 KB Output is correct
24 Correct 35 ms 4648 KB Output is correct
25 Correct 27 ms 4676 KB Output is correct
26 Correct 24 ms 4676 KB Output is correct
27 Correct 33 ms 4676 KB Output is correct
28 Correct 30 ms 4676 KB Output is correct
29 Correct 32 ms 4676 KB Output is correct
30 Correct 30 ms 4676 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 248 KB Output is correct
2 Correct 2 ms 436 KB Output is correct
3 Correct 4 ms 548 KB Output is correct
4 Correct 6 ms 808 KB Output is correct
5 Correct 6 ms 860 KB Output is correct
6 Correct 4 ms 884 KB Output is correct
7 Correct 5 ms 884 KB Output is correct
8 Correct 6 ms 884 KB Output is correct
9 Correct 4 ms 936 KB Output is correct
10 Correct 6 ms 936 KB Output is correct
11 Correct 5 ms 936 KB Output is correct
12 Correct 6 ms 936 KB Output is correct
13 Correct 9 ms 936 KB Output is correct
14 Correct 8 ms 936 KB Output is correct
15 Correct 5 ms 936 KB Output is correct
16 Correct 16 ms 1444 KB Output is correct
17 Correct 22 ms 2468 KB Output is correct
18 Correct 27 ms 3884 KB Output is correct
19 Correct 36 ms 4648 KB Output is correct
20 Correct 48 ms 4648 KB Output is correct
21 Correct 45 ms 4648 KB Output is correct
22 Correct 40 ms 4648 KB Output is correct
23 Correct 38 ms 4648 KB Output is correct
24 Correct 35 ms 4648 KB Output is correct
25 Correct 27 ms 4676 KB Output is correct
26 Correct 24 ms 4676 KB Output is correct
27 Correct 33 ms 4676 KB Output is correct
28 Correct 30 ms 4676 KB Output is correct
29 Correct 32 ms 4676 KB Output is correct
30 Correct 30 ms 4676 KB Output is correct
31 Correct 88 ms 9400 KB Output is correct
32 Correct 82 ms 12980 KB Output is correct
33 Correct 134 ms 18256 KB Output is correct
34 Correct 147 ms 20756 KB Output is correct
35 Correct 144 ms 20860 KB Output is correct
36 Correct 147 ms 20892 KB Output is correct
37 Correct 206 ms 20892 KB Output is correct
38 Correct 132 ms 20892 KB Output is correct
39 Correct 145 ms 20892 KB Output is correct
40 Correct 155 ms 20892 KB Output is correct
41 Correct 160 ms 20892 KB Output is correct
42 Correct 139 ms 20892 KB Output is correct
43 Correct 119 ms 20892 KB Output is correct
44 Correct 163 ms 20896 KB Output is correct
45 Correct 143 ms 20924 KB Output is correct
46 Correct 164 ms 20980 KB Output is correct
47 Correct 224 ms 20980 KB Output is correct
48 Correct 203 ms 20980 KB Output is correct
49 Correct 174 ms 20980 KB Output is correct
50 Correct 176 ms 20980 KB Output is correct
51 Correct 142 ms 20980 KB Output is correct
52 Correct 86 ms 20980 KB Output is correct
53 Correct 188 ms 20980 KB Output is correct
54 Correct 170 ms 20980 KB Output is correct
55 Correct 173 ms 20980 KB Output is correct
56 Correct 163 ms 20980 KB Output is correct
57 Correct 201 ms 20980 KB Output is correct
58 Correct 169 ms 20980 KB Output is correct
59 Correct 155 ms 20980 KB Output is correct
60 Correct 164 ms 20980 KB Output is correct