Submission #777854

# Submission time Handle Problem Language Result Execution time Memory
777854 2023-07-09T19:03:56 Z OrazB Xylophone (JOI18_xylophone) C++17
100 / 100
68 ms 384 KB
#include <bits/stdc++.h>
#include "xylophone.h"
using namespace std;
#define wr cout << "Continue debugging\n";
#define all(x) (x).begin(), (x).end()
#define ll long long int
#define pii pair <int, int>
#define pb push_back
#define ff first
#define ss second

int F(int n){
	int l = 1, r = n-1, pos;
	while(l <= r){
		int md = (l+r)>>1;
		int x = query(md, n);
		if (x != n-1) r = md - 1;
		else{
			pos = md;
			l = md + 1;
		}
	}
	return pos;
}

void solve(int n){
	int pos = F(n);
	vector<int> a(n+1), vis(n+2, 0);
	vis[1] = 1;
	a[pos] = 1;
	a[pos+1] = 1+query(pos, pos+1);
	vis[a[pos+1]] = 1;
	if (pos > 1){
		a[pos-1] = 1+query(pos-1, pos);
		vis[a[pos-1]] = 1;
	}
	for (int i = pos-2; i >= 1; i--){
		a[i] = a[i+1];
		int x = query(i, i+1);
		if (a[i]+x > n or vis[a[i]+x]){a[i] -= x; vis[a[i]] = 1; continue;}
		if (a[i]-x <= 0 or vis[a[i]-x]){a[i] += x; vis[a[i]] = 1; continue;} 
		int y = query(i, i+2);
		if (x == y){
			if (a[i+1] > a[i+2]) a[i] -= x;
			else a[i] += x;
		}else{
			if (abs(a[i+1]-a[i+2]) != y){
				if (a[i+1] > a[i+2]) a[i] += x;
				else a[i] -= x;
			}else{
				if (a[i+1] > a[i+2]) a[i] -= x;
				else a[i] += x;
			}
		}
		vis[a[i]] = 1;
	}
	for (int i = pos+2; i <= n; i++){
		a[i] = a[i-1];
		int x = query(i-1, i);
		if (a[i]+x > n or vis[a[i]+x]){a[i] -= x;continue;}
		if (a[i]-x <= 0 or vis[a[i]-x]){a[i] += x;continue;}
		int y = query(i-2, i);
		if (x == y){
			if (a[i-1] > a[i-2]) a[i] -= x;
			else a[i] += x;
		}else{
			if (abs(a[i-1]-a[i-2]) != y){
				if (a[i-1] > a[i-2]) a[i] += x;
				else a[i] -= x;
			}else{
				if (a[i-1] > a[i-2]) a[i] -= x;
				else a[i] += x;
			}
		}
		vis[a[i]] = 1;
	}
	for (int i = 1; i <= n; i++) answer(i, a[i]);
}

Compilation message

xylophone.cpp: In function 'int F(int)':
xylophone.cpp:23:9: warning: 'pos' may be used uninitialized in this function [-Wmaybe-uninitialized]
   23 |  return pos;
      |         ^~~
xylophone.cpp: In function 'void solve(int)':
xylophone.cpp:34:21: warning: 'pos' may be used uninitialized in this function [-Wmaybe-uninitialized]
   34 |   a[pos-1] = 1+query(pos-1, pos);
      |                ~~~~~^~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 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 1 ms 208 KB Output is correct
5 Correct 1 ms 208 KB Output is correct
6 Correct 1 ms 208 KB Output is correct
7 Correct 1 ms 208 KB Output is correct
8 Correct 2 ms 208 KB Output is correct
9 Correct 2 ms 208 KB Output is correct
10 Correct 1 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 1 ms 208 KB Output is correct
14 Correct 2 ms 208 KB Output is correct
15 Correct 1 ms 208 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 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 1 ms 208 KB Output is correct
5 Correct 1 ms 208 KB Output is correct
6 Correct 1 ms 208 KB Output is correct
7 Correct 1 ms 208 KB Output is correct
8 Correct 2 ms 208 KB Output is correct
9 Correct 2 ms 208 KB Output is correct
10 Correct 1 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 1 ms 208 KB Output is correct
14 Correct 2 ms 208 KB Output is correct
15 Correct 1 ms 208 KB Output is correct
16 Correct 3 ms 208 KB Output is correct
17 Correct 7 ms 208 KB Output is correct
18 Correct 8 ms 208 KB Output is correct
19 Correct 12 ms 208 KB Output is correct
20 Correct 14 ms 208 KB Output is correct
21 Correct 7 ms 208 KB Output is correct
22 Correct 12 ms 208 KB Output is correct
23 Correct 13 ms 208 KB Output is correct
24 Correct 8 ms 208 KB Output is correct
25 Correct 11 ms 284 KB Output is correct
26 Correct 13 ms 208 KB Output is correct
27 Correct 15 ms 208 KB Output is correct
28 Correct 14 ms 312 KB Output is correct
29 Correct 12 ms 208 KB Output is correct
30 Correct 11 ms 312 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 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 1 ms 208 KB Output is correct
5 Correct 1 ms 208 KB Output is correct
6 Correct 1 ms 208 KB Output is correct
7 Correct 1 ms 208 KB Output is correct
8 Correct 2 ms 208 KB Output is correct
9 Correct 2 ms 208 KB Output is correct
10 Correct 1 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 1 ms 208 KB Output is correct
14 Correct 2 ms 208 KB Output is correct
15 Correct 1 ms 208 KB Output is correct
16 Correct 3 ms 208 KB Output is correct
17 Correct 7 ms 208 KB Output is correct
18 Correct 8 ms 208 KB Output is correct
19 Correct 12 ms 208 KB Output is correct
20 Correct 14 ms 208 KB Output is correct
21 Correct 7 ms 208 KB Output is correct
22 Correct 12 ms 208 KB Output is correct
23 Correct 13 ms 208 KB Output is correct
24 Correct 8 ms 208 KB Output is correct
25 Correct 11 ms 284 KB Output is correct
26 Correct 13 ms 208 KB Output is correct
27 Correct 15 ms 208 KB Output is correct
28 Correct 14 ms 312 KB Output is correct
29 Correct 12 ms 208 KB Output is correct
30 Correct 11 ms 312 KB Output is correct
31 Correct 20 ms 300 KB Output is correct
32 Correct 22 ms 308 KB Output is correct
33 Correct 38 ms 316 KB Output is correct
34 Correct 25 ms 336 KB Output is correct
35 Correct 52 ms 336 KB Output is correct
36 Correct 58 ms 336 KB Output is correct
37 Correct 46 ms 336 KB Output is correct
38 Correct 56 ms 384 KB Output is correct
39 Correct 44 ms 328 KB Output is correct
40 Correct 58 ms 336 KB Output is correct
41 Correct 41 ms 336 KB Output is correct
42 Correct 35 ms 336 KB Output is correct
43 Correct 46 ms 316 KB Output is correct
44 Correct 50 ms 336 KB Output is correct
45 Correct 46 ms 336 KB Output is correct
46 Correct 49 ms 336 KB Output is correct
47 Correct 59 ms 336 KB Output is correct
48 Correct 44 ms 336 KB Output is correct
49 Correct 67 ms 336 KB Output is correct
50 Correct 56 ms 336 KB Output is correct
51 Correct 62 ms 328 KB Output is correct
52 Correct 53 ms 336 KB Output is correct
53 Correct 68 ms 336 KB Output is correct
54 Correct 50 ms 336 KB Output is correct
55 Correct 53 ms 336 KB Output is correct
56 Correct 53 ms 208 KB Output is correct
57 Correct 60 ms 336 KB Output is correct
58 Correct 53 ms 336 KB Output is correct
59 Correct 35 ms 320 KB Output is correct
60 Correct 56 ms 316 KB Output is correct