답안 #764518

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
764518 2023-06-23T14:10:47 Z sysia Xylophone (JOI18_xylophone) C++17
100 / 100
90 ms 432 KB
//Sylwia Sapkowska
#include <bits/stdc++.h>
#include "xylophone.h"
#pragma GCC optimize("O3", "unroll-loops")
using namespace std;

void __print(int x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << "'" << x << "'";}
void __print(const char *x) {cerr << '"' << x << '"';}
void __print(const string &x) {cerr << '"' << x << '"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ", "; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? ", " : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifdef LOCAL
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif

void solve(int n){
	vector<int>a(n+1);
	for (int i = 1; i<n; i++) a[i] = query(i, i+1);
	//a[i] = abs(p[i] - p[i+1])
	vector<int>dir(n+1);
	for (int i = 1; i+2 <= n; i++){
		int x = query(i, i+2);
		if (a[i] + a[i+1] == x){
			dir[i+1] = dir[i];
		} else {
			dir[i+1] = dir[i]^1;
		}
	}
	for (int rep = 0; rep < 2; rep++){
		vector<int>p(n+1);
		int mn = 0;
		for (int i = 1; i<n; i++){
			if (dir[i]) p[i+1] = p[i] + a[i];
			else p[i+1] = p[i] - a[i];
			mn = min(mn, p[i+1]);
		}
		for (int i = 1; i<=n; i++) {
			p[i] += (1-mn);
		}
		debug(p);
		bool was = 0;
		bool ok = 1;
		for (int i = 1; i<=n; i++){
			if (p[i] < 1 || p[i] > n) {
				ok = 0;
				break;
			}
			if (p[i] == 1) was = 1;
			if (p[i] == n){
				if (!was) ok = 0;
			}
		}
		if (ok){
			debug(p);
			for (int i = 1; i<=n; i++) answer(i, p[i]);
			return;
		}
		for (int i = 1; i<n; i++) dir[i]^=1;
	}
	assert(false);
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 208 KB Output is correct
2 Correct 0 ms 208 KB Output is correct
3 Correct 1 ms 208 KB Output is correct
4 Correct 2 ms 208 KB Output is correct
5 Correct 2 ms 208 KB Output is correct
6 Correct 2 ms 208 KB Output is correct
7 Correct 2 ms 208 KB Output is correct
8 Correct 1 ms 208 KB Output is correct
9 Correct 2 ms 208 KB Output is correct
10 Correct 2 ms 208 KB Output is correct
11 Correct 2 ms 208 KB Output is correct
12 Correct 2 ms 208 KB Output is correct
13 Correct 2 ms 208 KB Output is correct
14 Correct 1 ms 208 KB Output is correct
15 Correct 1 ms 208 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 208 KB Output is correct
2 Correct 0 ms 208 KB Output is correct
3 Correct 1 ms 208 KB Output is correct
4 Correct 2 ms 208 KB Output is correct
5 Correct 2 ms 208 KB Output is correct
6 Correct 2 ms 208 KB Output is correct
7 Correct 2 ms 208 KB Output is correct
8 Correct 1 ms 208 KB Output is correct
9 Correct 2 ms 208 KB Output is correct
10 Correct 2 ms 208 KB Output is correct
11 Correct 2 ms 208 KB Output is correct
12 Correct 2 ms 208 KB Output is correct
13 Correct 2 ms 208 KB Output is correct
14 Correct 1 ms 208 KB Output is correct
15 Correct 1 ms 208 KB Output is correct
16 Correct 4 ms 308 KB Output is correct
17 Correct 9 ms 300 KB Output is correct
18 Correct 15 ms 300 KB Output is correct
19 Correct 12 ms 304 KB Output is correct
20 Correct 17 ms 300 KB Output is correct
21 Correct 12 ms 208 KB Output is correct
22 Correct 16 ms 288 KB Output is correct
23 Correct 18 ms 300 KB Output is correct
24 Correct 16 ms 300 KB Output is correct
25 Correct 17 ms 304 KB Output is correct
26 Correct 7 ms 300 KB Output is correct
27 Correct 12 ms 304 KB Output is correct
28 Correct 18 ms 208 KB Output is correct
29 Correct 11 ms 304 KB Output is correct
30 Correct 14 ms 300 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 208 KB Output is correct
2 Correct 0 ms 208 KB Output is correct
3 Correct 1 ms 208 KB Output is correct
4 Correct 2 ms 208 KB Output is correct
5 Correct 2 ms 208 KB Output is correct
6 Correct 2 ms 208 KB Output is correct
7 Correct 2 ms 208 KB Output is correct
8 Correct 1 ms 208 KB Output is correct
9 Correct 2 ms 208 KB Output is correct
10 Correct 2 ms 208 KB Output is correct
11 Correct 2 ms 208 KB Output is correct
12 Correct 2 ms 208 KB Output is correct
13 Correct 2 ms 208 KB Output is correct
14 Correct 1 ms 208 KB Output is correct
15 Correct 1 ms 208 KB Output is correct
16 Correct 4 ms 308 KB Output is correct
17 Correct 9 ms 300 KB Output is correct
18 Correct 15 ms 300 KB Output is correct
19 Correct 12 ms 304 KB Output is correct
20 Correct 17 ms 300 KB Output is correct
21 Correct 12 ms 208 KB Output is correct
22 Correct 16 ms 288 KB Output is correct
23 Correct 18 ms 300 KB Output is correct
24 Correct 16 ms 300 KB Output is correct
25 Correct 17 ms 304 KB Output is correct
26 Correct 7 ms 300 KB Output is correct
27 Correct 12 ms 304 KB Output is correct
28 Correct 18 ms 208 KB Output is correct
29 Correct 11 ms 304 KB Output is correct
30 Correct 14 ms 300 KB Output is correct
31 Correct 37 ms 300 KB Output is correct
32 Correct 51 ms 304 KB Output is correct
33 Correct 48 ms 424 KB Output is correct
34 Correct 75 ms 320 KB Output is correct
35 Correct 81 ms 320 KB Output is correct
36 Correct 56 ms 300 KB Output is correct
37 Correct 78 ms 324 KB Output is correct
38 Correct 65 ms 320 KB Output is correct
39 Correct 81 ms 320 KB Output is correct
40 Correct 61 ms 324 KB Output is correct
41 Correct 73 ms 432 KB Output is correct
42 Correct 81 ms 320 KB Output is correct
43 Correct 82 ms 308 KB Output is correct
44 Correct 90 ms 312 KB Output is correct
45 Correct 77 ms 424 KB Output is correct
46 Correct 79 ms 316 KB Output is correct
47 Correct 41 ms 316 KB Output is correct
48 Correct 59 ms 296 KB Output is correct
49 Correct 63 ms 320 KB Output is correct
50 Correct 71 ms 312 KB Output is correct
51 Correct 82 ms 316 KB Output is correct
52 Correct 58 ms 300 KB Output is correct
53 Correct 69 ms 296 KB Output is correct
54 Correct 79 ms 316 KB Output is correct
55 Correct 69 ms 316 KB Output is correct
56 Correct 80 ms 392 KB Output is correct
57 Correct 80 ms 320 KB Output is correct
58 Correct 60 ms 328 KB Output is correct
59 Correct 63 ms 320 KB Output is correct
60 Correct 72 ms 380 KB Output is correct