답안 #470797

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
470797 2021-09-05T15:49:27 Z Ya_Ali Xylophone (JOI18_xylophone) C++17
100 / 100
137 ms 496 KB
/* ** *** In the name of God *** ** */
// Only Haider is Amir al-Momenin
#include <bits/stdc++.h>
#include "xylophone.h"
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pll;
const ll maxn = 5e3 + 5;
const ll mod = 1e9 + 7;
#define endl '\n'
#define all(x) x.begin(), x.end()
#define kill(x) return cout << x, 0
#define m (lx + rx) / 2
#define L 2 * x + 1
#define R L + 1
ll b1[maxn], b2[maxn], d1[maxn], d2[maxn];
bool flag1[maxn], flag2[maxn];
void build_b1(int n){
	flag1[1] = 1;
        for(ll i = 1; i < n; i ++){     
                if(flag1[i])b1[i + 1] = b1[i] + d1[i];
                else b1[i + 1] = b1[i] - d1[i];
                if(i < n - 1){
                        if(d2[i] == d1[i] + d1[i + 1])flag1[i + 1] = flag1[i];
                        else flag1[i + 1] = !flag1[i];
                }
        }
	ll mn = (n * 10);
	for(ll i = 1; i <= n; i++) mn = min(mn, b1[i]);
	for(ll i = 1; i <= n; i++) b1[i] += (1 - mn);
}
void build_b2(int n){
        flag2[1] = 0;
        for(ll i = 1; i < n; i ++){
                if(flag2[i])b2[i + 1] = b2[i] + d1[i];
                else b2[i + 1] = b2[i] - d1[i];
                if(i < n - 1){
                        if(d2[i] == d1[i] + d1[i + 1])flag2[i + 1] = flag2[i];
                        else flag2[i + 1] = !flag2[i];
                }
        }
        ll mn = (n * 10);
        for(ll i = 1; i <= n; i++) mn = min(mn, b2[i]);
        for(ll i = 1; i <= n; i++) b2[i] += (1 - mn);
}
void solve(int n){
	for(ll i = 1; i < n; i ++)d1[i] = query(i, i + 1);
	for(ll i = 1; i < n - 1; i ++)d2[i] = query(i, i + 2);
	build_b1(n); build_b2(n);
	ll p1, pn;
	for(ll i = 1; i <= n; i ++){
		if(b1[i] == 1)p1 = i;
		if(b1[i] == n)pn = i;
	}
	if(p1 > pn)
		for(ll i = 1; i <= n; i ++)answer(i, b2[i]);
	else
		for(ll i = 1; i <= n; i ++)answer(i, b1[i]);
}

Compilation message

xylophone.cpp: In function 'void solve(int)':
xylophone.cpp:55:2: warning: 'pn' may be used uninitialized in this function [-Wmaybe-uninitialized]
   55 |  if(p1 > pn)
      |  ^~
xylophone.cpp:55:2: warning: 'p1' may be used uninitialized in this function [-Wmaybe-uninitialized]
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 200 KB Output is correct
2 Correct 1 ms 200 KB Output is correct
3 Correct 1 ms 200 KB Output is correct
4 Correct 3 ms 200 KB Output is correct
5 Correct 2 ms 308 KB Output is correct
6 Correct 3 ms 328 KB Output is correct
7 Correct 3 ms 200 KB Output is correct
8 Correct 2 ms 200 KB Output is correct
9 Correct 3 ms 200 KB Output is correct
10 Correct 3 ms 200 KB Output is correct
11 Correct 3 ms 328 KB Output is correct
12 Correct 3 ms 200 KB Output is correct
13 Correct 2 ms 200 KB Output is correct
14 Correct 3 ms 328 KB Output is correct
15 Correct 2 ms 304 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 200 KB Output is correct
2 Correct 1 ms 200 KB Output is correct
3 Correct 1 ms 200 KB Output is correct
4 Correct 3 ms 200 KB Output is correct
5 Correct 2 ms 308 KB Output is correct
6 Correct 3 ms 328 KB Output is correct
7 Correct 3 ms 200 KB Output is correct
8 Correct 2 ms 200 KB Output is correct
9 Correct 3 ms 200 KB Output is correct
10 Correct 3 ms 200 KB Output is correct
11 Correct 3 ms 328 KB Output is correct
12 Correct 3 ms 200 KB Output is correct
13 Correct 2 ms 200 KB Output is correct
14 Correct 3 ms 328 KB Output is correct
15 Correct 2 ms 304 KB Output is correct
16 Correct 5 ms 200 KB Output is correct
17 Correct 10 ms 328 KB Output is correct
18 Correct 21 ms 308 KB Output is correct
19 Correct 25 ms 312 KB Output is correct
20 Correct 18 ms 316 KB Output is correct
21 Correct 14 ms 316 KB Output is correct
22 Correct 18 ms 312 KB Output is correct
23 Correct 19 ms 308 KB Output is correct
24 Correct 17 ms 324 KB Output is correct
25 Correct 27 ms 432 KB Output is correct
26 Correct 24 ms 300 KB Output is correct
27 Correct 26 ms 300 KB Output is correct
28 Correct 33 ms 320 KB Output is correct
29 Correct 18 ms 320 KB Output is correct
30 Correct 17 ms 320 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 200 KB Output is correct
2 Correct 1 ms 200 KB Output is correct
3 Correct 1 ms 200 KB Output is correct
4 Correct 3 ms 200 KB Output is correct
5 Correct 2 ms 308 KB Output is correct
6 Correct 3 ms 328 KB Output is correct
7 Correct 3 ms 200 KB Output is correct
8 Correct 2 ms 200 KB Output is correct
9 Correct 3 ms 200 KB Output is correct
10 Correct 3 ms 200 KB Output is correct
11 Correct 3 ms 328 KB Output is correct
12 Correct 3 ms 200 KB Output is correct
13 Correct 2 ms 200 KB Output is correct
14 Correct 3 ms 328 KB Output is correct
15 Correct 2 ms 304 KB Output is correct
16 Correct 5 ms 200 KB Output is correct
17 Correct 10 ms 328 KB Output is correct
18 Correct 21 ms 308 KB Output is correct
19 Correct 25 ms 312 KB Output is correct
20 Correct 18 ms 316 KB Output is correct
21 Correct 14 ms 316 KB Output is correct
22 Correct 18 ms 312 KB Output is correct
23 Correct 19 ms 308 KB Output is correct
24 Correct 17 ms 324 KB Output is correct
25 Correct 27 ms 432 KB Output is correct
26 Correct 24 ms 300 KB Output is correct
27 Correct 26 ms 300 KB Output is correct
28 Correct 33 ms 320 KB Output is correct
29 Correct 18 ms 320 KB Output is correct
30 Correct 17 ms 320 KB Output is correct
31 Correct 24 ms 368 KB Output is correct
32 Correct 75 ms 324 KB Output is correct
33 Correct 91 ms 440 KB Output is correct
34 Correct 98 ms 432 KB Output is correct
35 Correct 131 ms 420 KB Output is correct
36 Correct 120 ms 448 KB Output is correct
37 Correct 128 ms 468 KB Output is correct
38 Correct 119 ms 448 KB Output is correct
39 Correct 100 ms 368 KB Output is correct
40 Correct 102 ms 436 KB Output is correct
41 Correct 123 ms 364 KB Output is correct
42 Correct 57 ms 424 KB Output is correct
43 Correct 116 ms 428 KB Output is correct
44 Correct 123 ms 428 KB Output is correct
45 Correct 92 ms 448 KB Output is correct
46 Correct 110 ms 356 KB Output is correct
47 Correct 137 ms 364 KB Output is correct
48 Correct 111 ms 424 KB Output is correct
49 Correct 94 ms 448 KB Output is correct
50 Correct 123 ms 436 KB Output is correct
51 Correct 53 ms 472 KB Output is correct
52 Correct 79 ms 436 KB Output is correct
53 Correct 89 ms 432 KB Output is correct
54 Correct 108 ms 468 KB Output is correct
55 Correct 84 ms 472 KB Output is correct
56 Correct 114 ms 432 KB Output is correct
57 Correct 126 ms 480 KB Output is correct
58 Correct 126 ms 480 KB Output is correct
59 Correct 131 ms 468 KB Output is correct
60 Correct 114 ms 496 KB Output is correct