답안 #102472

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
102472 2019-03-25T07:48:53 Z DrumpfTheGodEmperor Xylophone (JOI18_xylophone) C++14
100 / 100
92 ms 448 KB
#include <bits/stdc++.h>
#include "xylophone.h"
#define bp __builtin_popcountll
#define pb push_back
#define in(s) freopen(s, "r", stdin);
#define inout(s, end1, end2) freopen((string(s) + "." + end1).c_str(), "r", stdin),\
		freopen((string(s) + "." + end2).c_str(), "w", stdout);
#define fi first
#define se second
#define bw(i, r, l) for (int i = r - 1; i >= l; i--)
#define fw(i, l, r) for (int i = l; i < r; i++)
#define fa(i, x) for (auto i: x)
using namespace std;
const int mod = 1e9 + 7, inf = 1061109567;
const long long infll = 4557430888798830399;
const int N = 5005;
int res[N], a[N];
bool bigger[N];
int ask(int l, int r) { return query(l + 1, r + 1); }
void ans(int i, int a) { answer(i + 1, a); }
void solve(int n) {
	//bigger[i] = 1 if a[i] > a[i + 1]
	bigger[0] = 0;
	res[0] = ask(0, 1);
	fw (i, 1, n - 1) {
		int tmp1 = ask(i, i + 1), tmp2 = ask(i - 1, i + 1);
		res[i] = tmp1;
		if (tmp2 != tmp1 && tmp2 != res[i - 1]) {
			if (bigger[i - 1]) bigger[i] = 1;
			else bigger[i] = 0;
		} else {
			if (bigger[i - 1]) bigger[i] = 0;
			else bigger[i] = 1;
		}
	}
	int plusmx = 0, delmx = 0, plusmxpos = -1, delmxpos = -1;
	int cur = 0;
	fw (i, 0, n - 1) {
		if (bigger[i]) cur -= res[i];
		else cur += res[i];
		if (cur > plusmx) {
			plusmx = cur;
			plusmxpos = i;
		}
		if (cur < delmx) {
			delmx = cur;
			delmxpos = i;
		}
	}
	if (delmxpos > plusmxpos) {
		fw (i, 0, n - 1) bigger[i] ^= 1;
	}
	a[0] = 0;
	fw (i, 0, n - 1) {
		if (bigger[i]) a[i + 1] = a[i] - res[i];
		else a[i + 1] = a[i] + res[i];
	}
	int mnval = 0;
	fw (i, 1, n) mnval = min(mnval, a[i]);
	int offset = -mnval + 1;
	fw (i, 0, n) ans(i, a[i] + offset);
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 2 ms 256 KB Output is correct
3 Correct 3 ms 256 KB Output is correct
4 Correct 3 ms 384 KB Output is correct
5 Correct 3 ms 256 KB Output is correct
6 Correct 5 ms 384 KB Output is correct
7 Correct 4 ms 256 KB Output is correct
8 Correct 3 ms 328 KB Output is correct
9 Correct 3 ms 324 KB Output is correct
10 Correct 4 ms 384 KB Output is correct
11 Correct 4 ms 304 KB Output is correct
12 Correct 5 ms 384 KB Output is correct
13 Correct 4 ms 256 KB Output is correct
14 Correct 3 ms 256 KB Output is correct
15 Correct 4 ms 256 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 2 ms 256 KB Output is correct
3 Correct 3 ms 256 KB Output is correct
4 Correct 3 ms 384 KB Output is correct
5 Correct 3 ms 256 KB Output is correct
6 Correct 5 ms 384 KB Output is correct
7 Correct 4 ms 256 KB Output is correct
8 Correct 3 ms 328 KB Output is correct
9 Correct 3 ms 324 KB Output is correct
10 Correct 4 ms 384 KB Output is correct
11 Correct 4 ms 304 KB Output is correct
12 Correct 5 ms 384 KB Output is correct
13 Correct 4 ms 256 KB Output is correct
14 Correct 3 ms 256 KB Output is correct
15 Correct 4 ms 256 KB Output is correct
16 Correct 4 ms 256 KB Output is correct
17 Correct 10 ms 384 KB Output is correct
18 Correct 16 ms 256 KB Output is correct
19 Correct 19 ms 332 KB Output is correct
20 Correct 14 ms 384 KB Output is correct
21 Correct 17 ms 384 KB Output is correct
22 Correct 14 ms 256 KB Output is correct
23 Correct 18 ms 384 KB Output is correct
24 Correct 21 ms 384 KB Output is correct
25 Correct 16 ms 384 KB Output is correct
26 Correct 20 ms 416 KB Output is correct
27 Correct 15 ms 384 KB Output is correct
28 Correct 15 ms 448 KB Output is correct
29 Correct 18 ms 256 KB Output is correct
30 Correct 17 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 2 ms 256 KB Output is correct
3 Correct 3 ms 256 KB Output is correct
4 Correct 3 ms 384 KB Output is correct
5 Correct 3 ms 256 KB Output is correct
6 Correct 5 ms 384 KB Output is correct
7 Correct 4 ms 256 KB Output is correct
8 Correct 3 ms 328 KB Output is correct
9 Correct 3 ms 324 KB Output is correct
10 Correct 4 ms 384 KB Output is correct
11 Correct 4 ms 304 KB Output is correct
12 Correct 5 ms 384 KB Output is correct
13 Correct 4 ms 256 KB Output is correct
14 Correct 3 ms 256 KB Output is correct
15 Correct 4 ms 256 KB Output is correct
16 Correct 4 ms 256 KB Output is correct
17 Correct 10 ms 384 KB Output is correct
18 Correct 16 ms 256 KB Output is correct
19 Correct 19 ms 332 KB Output is correct
20 Correct 14 ms 384 KB Output is correct
21 Correct 17 ms 384 KB Output is correct
22 Correct 14 ms 256 KB Output is correct
23 Correct 18 ms 384 KB Output is correct
24 Correct 21 ms 384 KB Output is correct
25 Correct 16 ms 384 KB Output is correct
26 Correct 20 ms 416 KB Output is correct
27 Correct 15 ms 384 KB Output is correct
28 Correct 15 ms 448 KB Output is correct
29 Correct 18 ms 256 KB Output is correct
30 Correct 17 ms 384 KB Output is correct
31 Correct 37 ms 340 KB Output is correct
32 Correct 44 ms 336 KB Output is correct
33 Correct 72 ms 384 KB Output is correct
34 Correct 76 ms 384 KB Output is correct
35 Correct 76 ms 384 KB Output is correct
36 Correct 85 ms 332 KB Output is correct
37 Correct 73 ms 384 KB Output is correct
38 Correct 50 ms 416 KB Output is correct
39 Correct 81 ms 384 KB Output is correct
40 Correct 92 ms 376 KB Output is correct
41 Correct 67 ms 380 KB Output is correct
42 Correct 66 ms 384 KB Output is correct
43 Correct 81 ms 376 KB Output is correct
44 Correct 67 ms 384 KB Output is correct
45 Correct 79 ms 384 KB Output is correct
46 Correct 68 ms 388 KB Output is correct
47 Correct 46 ms 404 KB Output is correct
48 Correct 79 ms 384 KB Output is correct
49 Correct 63 ms 324 KB Output is correct
50 Correct 88 ms 336 KB Output is correct
51 Correct 70 ms 420 KB Output is correct
52 Correct 80 ms 376 KB Output is correct
53 Correct 81 ms 336 KB Output is correct
54 Correct 55 ms 432 KB Output is correct
55 Correct 90 ms 256 KB Output is correct
56 Correct 79 ms 380 KB Output is correct
57 Correct 72 ms 384 KB Output is correct
58 Correct 75 ms 428 KB Output is correct
59 Correct 79 ms 328 KB Output is correct
60 Correct 61 ms 336 KB Output is correct