Submission #470693

# Submission time Handle Problem Language Result Execution time Memory
470693 2021-09-05T06:28:34 Z Millad Xylophone (JOI18_xylophone) C++14
100 / 100
127 ms 576 KB
// In the name of god
#include "xylophone.h"
#include <bits/stdc++.h>

#define F first
#define S second
#define pb push_back
#define debug(x) cerr << #x << " : " << x << '\n'

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pll;

const ll maxn = 5e3 + 5;

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:56:2: warning: 'pn' may be used uninitialized in this function [-Wmaybe-uninitialized]
   56 |  if(p1 > pn)
      |  ^~
xylophone.cpp:56:2: warning: 'p1' may be used uninitialized in this function [-Wmaybe-uninitialized]
# Verdict Execution time Memory Grader output
1 Correct 1 ms 200 KB Output is correct
2 Correct 0 ms 200 KB Output is correct
3 Correct 1 ms 312 KB Output is correct
4 Correct 3 ms 308 KB Output is correct
5 Correct 3 ms 308 KB Output is correct
6 Correct 2 ms 200 KB Output is correct
7 Correct 3 ms 200 KB Output is correct
8 Correct 3 ms 200 KB Output is correct
9 Correct 3 ms 200 KB Output is correct
10 Correct 2 ms 200 KB Output is correct
11 Correct 1 ms 200 KB Output is correct
12 Correct 3 ms 200 KB Output is correct
13 Correct 1 ms 308 KB Output is correct
14 Correct 4 ms 200 KB Output is correct
15 Correct 3 ms 200 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 200 KB Output is correct
2 Correct 0 ms 200 KB Output is correct
3 Correct 1 ms 312 KB Output is correct
4 Correct 3 ms 308 KB Output is correct
5 Correct 3 ms 308 KB Output is correct
6 Correct 2 ms 200 KB Output is correct
7 Correct 3 ms 200 KB Output is correct
8 Correct 3 ms 200 KB Output is correct
9 Correct 3 ms 200 KB Output is correct
10 Correct 2 ms 200 KB Output is correct
11 Correct 1 ms 200 KB Output is correct
12 Correct 3 ms 200 KB Output is correct
13 Correct 1 ms 308 KB Output is correct
14 Correct 4 ms 200 KB Output is correct
15 Correct 3 ms 200 KB Output is correct
16 Correct 6 ms 312 KB Output is correct
17 Correct 12 ms 328 KB Output is correct
18 Correct 16 ms 320 KB Output is correct
19 Correct 22 ms 312 KB Output is correct
20 Correct 26 ms 304 KB Output is correct
21 Correct 17 ms 316 KB Output is correct
22 Correct 23 ms 320 KB Output is correct
23 Correct 20 ms 304 KB Output is correct
24 Correct 20 ms 316 KB Output is correct
25 Correct 23 ms 308 KB Output is correct
26 Correct 24 ms 320 KB Output is correct
27 Correct 18 ms 316 KB Output is correct
28 Correct 25 ms 308 KB Output is correct
29 Correct 28 ms 312 KB Output is correct
30 Correct 18 ms 320 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 200 KB Output is correct
2 Correct 0 ms 200 KB Output is correct
3 Correct 1 ms 312 KB Output is correct
4 Correct 3 ms 308 KB Output is correct
5 Correct 3 ms 308 KB Output is correct
6 Correct 2 ms 200 KB Output is correct
7 Correct 3 ms 200 KB Output is correct
8 Correct 3 ms 200 KB Output is correct
9 Correct 3 ms 200 KB Output is correct
10 Correct 2 ms 200 KB Output is correct
11 Correct 1 ms 200 KB Output is correct
12 Correct 3 ms 200 KB Output is correct
13 Correct 1 ms 308 KB Output is correct
14 Correct 4 ms 200 KB Output is correct
15 Correct 3 ms 200 KB Output is correct
16 Correct 6 ms 312 KB Output is correct
17 Correct 12 ms 328 KB Output is correct
18 Correct 16 ms 320 KB Output is correct
19 Correct 22 ms 312 KB Output is correct
20 Correct 26 ms 304 KB Output is correct
21 Correct 17 ms 316 KB Output is correct
22 Correct 23 ms 320 KB Output is correct
23 Correct 20 ms 304 KB Output is correct
24 Correct 20 ms 316 KB Output is correct
25 Correct 23 ms 308 KB Output is correct
26 Correct 24 ms 320 KB Output is correct
27 Correct 18 ms 316 KB Output is correct
28 Correct 25 ms 308 KB Output is correct
29 Correct 28 ms 312 KB Output is correct
30 Correct 18 ms 320 KB Output is correct
31 Correct 53 ms 320 KB Output is correct
32 Correct 74 ms 320 KB Output is correct
33 Correct 110 ms 352 KB Output is correct
34 Correct 124 ms 456 KB Output is correct
35 Correct 120 ms 436 KB Output is correct
36 Correct 118 ms 428 KB Output is correct
37 Correct 122 ms 368 KB Output is correct
38 Correct 89 ms 428 KB Output is correct
39 Correct 88 ms 428 KB Output is correct
40 Correct 99 ms 576 KB Output is correct
41 Correct 79 ms 452 KB Output is correct
42 Correct 126 ms 452 KB Output is correct
43 Correct 115 ms 448 KB Output is correct
44 Correct 80 ms 432 KB Output is correct
45 Correct 127 ms 448 KB Output is correct
46 Correct 127 ms 440 KB Output is correct
47 Correct 121 ms 576 KB Output is correct
48 Correct 99 ms 352 KB Output is correct
49 Correct 102 ms 556 KB Output is correct
50 Correct 91 ms 428 KB Output is correct
51 Correct 120 ms 468 KB Output is correct
52 Correct 116 ms 476 KB Output is correct
53 Correct 112 ms 468 KB Output is correct
54 Correct 89 ms 448 KB Output is correct
55 Correct 112 ms 456 KB Output is correct
56 Correct 96 ms 448 KB Output is correct
57 Correct 109 ms 448 KB Output is correct
58 Correct 97 ms 352 KB Output is correct
59 Correct 104 ms 424 KB Output is correct
60 Correct 127 ms 428 KB Output is correct