답안 #781057

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
781057 2023-07-12T16:28:37 Z sadsa Xylophone (JOI18_xylophone) C++17
100 / 100
264 ms 98768 KB
#include "xylophone.h"

#include <bits/stdc++.h>
using namespace std;

using ll = long long;
using vi = vector<int>;
using ii = tuple<int, int>;
using vii = vector<ii>;

constexpr int iINF = numeric_limits<int>::max();
constexpr ll lINF = numeric_limits<ll>::max();

template <typename T>
void DBG(T&& arg) {
    cerr << arg << '\n';
}

template <typename T, typename... Ts>
void DBG(T&& x, Ts&&... y) {
    cerr << x << ' ';
    DBG(y...);
}

static vector<vi> qcache;
int queries;

int q(int l, int r) {
	if (l > r) swap(l, r);

	int Q;

	if (l == r) Q = 0;
	else {
		if (qcache[l][r] == -1) queries++;
		Q = (qcache[l][r] != -1)? qcache[l][r]: (qcache[l][r] = query(l, r));
	}

	DBG("query:", l, r, "V:", Q);

	return Q;
}

// finds a2
int get_next(int a0, int a1, int q02, int q12) {
	int a2;

	int q01 = abs(a1 - a0);

	if (q01 == q02) {
		DBG("WOOF");
		// minmax didnt change => ai2 between ai0 and ai1
		if (a0 < a1) a2 = a1 - q12;
		else a2 = a1 + q12;
	} else {
		DBG("MIAUW");
		if (a0 < a1) {
			if (q12 >= q02) a2 = a1 - q12;
			else a2 = a1 + q12;
		} else {
			if (q12 == q02) a2 = a1 + q12;
			else if (q12 < q02) a2 = a1 - q12;
			else a2 = a1 + q12;
		}
	}

	return a2;
}

void solve(int N) {
	qcache.clear();
	qcache.resize(N+1, vi(N+1, -1));
	queries = 0;

	vi ans(N+1);
	ans[2] = q(1, 2);

	for (int i = 1; i+2 <= N; ++i) {
		int i0=i;
		int i1=i+1;
		int i2=i+2;

		int q02 = q(i0, i2);
		int q12 = q(i1, i2);

		ans[i2] = get_next(ans[i0], ans[i1], q02, q12);
	}

	DBG(queries);

	auto [mi, ma] = minmax_element(ans.begin()+1, ans.end());

	if (mi < ma) {
		DBG("good first guess");
		int offset = N - *ma;
		for (int i = 1; i <= N; ++i) {
			DBG(offset + ans[i]);
			answer(i, ans[i] + offset);
		}
	} else {
		DBG("bad first guess");
		int offset = *ma + 1;
		for (int i = 1; i <= N; ++i) {
			DBG(offset - ans[i]);
			answer(i, offset - ans[i]);
		}
	}
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 208 KB Output is correct
2 Correct 0 ms 300 KB Output is correct
3 Correct 2 ms 208 KB Output is correct
4 Correct 4 ms 336 KB Output is correct
5 Correct 4 ms 336 KB Output is correct
6 Correct 6 ms 348 KB Output is correct
7 Correct 4 ms 336 KB Output is correct
8 Correct 4 ms 336 KB Output is correct
9 Correct 4 ms 336 KB Output is correct
10 Correct 4 ms 336 KB Output is correct
11 Correct 4 ms 348 KB Output is correct
12 Correct 4 ms 336 KB Output is correct
13 Correct 5 ms 336 KB Output is correct
14 Correct 5 ms 344 KB Output is correct
15 Correct 6 ms 344 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 208 KB Output is correct
2 Correct 0 ms 300 KB Output is correct
3 Correct 2 ms 208 KB Output is correct
4 Correct 4 ms 336 KB Output is correct
5 Correct 4 ms 336 KB Output is correct
6 Correct 6 ms 348 KB Output is correct
7 Correct 4 ms 336 KB Output is correct
8 Correct 4 ms 336 KB Output is correct
9 Correct 4 ms 336 KB Output is correct
10 Correct 4 ms 336 KB Output is correct
11 Correct 4 ms 348 KB Output is correct
12 Correct 4 ms 336 KB Output is correct
13 Correct 5 ms 336 KB Output is correct
14 Correct 5 ms 344 KB Output is correct
15 Correct 6 ms 344 KB Output is correct
16 Correct 9 ms 464 KB Output is correct
17 Correct 19 ms 1232 KB Output is correct
18 Correct 36 ms 2984 KB Output is correct
19 Correct 54 ms 4268 KB Output is correct
20 Correct 42 ms 4176 KB Output is correct
21 Correct 43 ms 4264 KB Output is correct
22 Correct 50 ms 4372 KB Output is correct
23 Correct 54 ms 4276 KB Output is correct
24 Correct 55 ms 4264 KB Output is correct
25 Correct 39 ms 4276 KB Output is correct
26 Correct 53 ms 4268 KB Output is correct
27 Correct 40 ms 4272 KB Output is correct
28 Correct 49 ms 4176 KB Output is correct
29 Correct 40 ms 4280 KB Output is correct
30 Correct 54 ms 4276 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 208 KB Output is correct
2 Correct 0 ms 300 KB Output is correct
3 Correct 2 ms 208 KB Output is correct
4 Correct 4 ms 336 KB Output is correct
5 Correct 4 ms 336 KB Output is correct
6 Correct 6 ms 348 KB Output is correct
7 Correct 4 ms 336 KB Output is correct
8 Correct 4 ms 336 KB Output is correct
9 Correct 4 ms 336 KB Output is correct
10 Correct 4 ms 336 KB Output is correct
11 Correct 4 ms 348 KB Output is correct
12 Correct 4 ms 336 KB Output is correct
13 Correct 5 ms 336 KB Output is correct
14 Correct 5 ms 344 KB Output is correct
15 Correct 6 ms 344 KB Output is correct
16 Correct 9 ms 464 KB Output is correct
17 Correct 19 ms 1232 KB Output is correct
18 Correct 36 ms 2984 KB Output is correct
19 Correct 54 ms 4268 KB Output is correct
20 Correct 42 ms 4176 KB Output is correct
21 Correct 43 ms 4264 KB Output is correct
22 Correct 50 ms 4372 KB Output is correct
23 Correct 54 ms 4276 KB Output is correct
24 Correct 55 ms 4264 KB Output is correct
25 Correct 39 ms 4276 KB Output is correct
26 Correct 53 ms 4268 KB Output is correct
27 Correct 40 ms 4272 KB Output is correct
28 Correct 49 ms 4176 KB Output is correct
29 Correct 40 ms 4280 KB Output is correct
30 Correct 54 ms 4276 KB Output is correct
31 Correct 109 ms 18752 KB Output is correct
32 Correct 135 ms 37884 KB Output is correct
33 Correct 198 ms 74928 KB Output is correct
34 Correct 257 ms 98476 KB Output is correct
35 Correct 229 ms 98608 KB Output is correct
36 Correct 219 ms 98628 KB Output is correct
37 Correct 223 ms 98624 KB Output is correct
38 Correct 264 ms 98564 KB Output is correct
39 Correct 219 ms 98508 KB Output is correct
40 Correct 224 ms 98704 KB Output is correct
41 Correct 225 ms 98620 KB Output is correct
42 Correct 224 ms 98632 KB Output is correct
43 Correct 242 ms 98768 KB Output is correct
44 Correct 241 ms 98640 KB Output is correct
45 Correct 218 ms 98748 KB Output is correct
46 Correct 260 ms 98624 KB Output is correct
47 Correct 241 ms 98616 KB Output is correct
48 Correct 259 ms 98632 KB Output is correct
49 Correct 228 ms 98628 KB Output is correct
50 Correct 246 ms 98632 KB Output is correct
51 Correct 220 ms 98656 KB Output is correct
52 Correct 237 ms 98760 KB Output is correct
53 Correct 247 ms 98632 KB Output is correct
54 Correct 241 ms 98632 KB Output is correct
55 Correct 249 ms 98764 KB Output is correct
56 Correct 225 ms 98580 KB Output is correct
57 Correct 237 ms 98680 KB Output is correct
58 Correct 233 ms 98632 KB Output is correct
59 Correct 239 ms 98588 KB Output is correct
60 Correct 226 ms 98632 KB Output is correct