Submission #1070489

# Submission time Handle Problem Language Result Execution time Memory
1070489 2024-08-22T14:41:05 Z _8_8_ Xylophone (JOI18_xylophone) C++17
47 / 100
58 ms 596 KB
#include "xylophone.h"
#include <bits/stdc++.h>
using namespace std;
int p[5002],a[5002];
void solve(int n) {
	memset(p,0,sizeof(p));
	memset(a,0,sizeof(a));
	int nd = n - 1;
	int l = 1,r = n;
	while(r - l > 1) {
		int mid = (l + r) >> 1;
		if(query(1,mid) == nd) {
			r = mid;
		} else {
			l = mid;
		}
	}
	p[n] = r;
	l = 1,r = p[n];
	while(r - l > 1) {
		int mid = (l + r) >> 1;
		if(query(mid,p[n]) == nd) {
			l = mid;
		} else {
			r = mid;
		}
	}
	p[1] = l;
	a[p[1]] = 1;
	a[p[n]] = n;
	int mx = 1;
	for(int i = p[1] - 1;i >= 1;i--) {
		int val, T;
		T = query(i,p[1]);
		if(T != mx - 1) {
			val = mx = 1 + T;
		} else {
			int t2, t1;
			t2 = query(i,i + 2);
			t1 = query(i + 1,i + 2);
			int t = query(i,i + 1);
			if(a[i + 2] > a[i + 1]) {
				if(t2 == a[i + 2] - (a[i + 1] - t)) {
					val = a[i + 1] - t;
				} else {
					val = a[i + 1] + t;
				}
			} else {
				if(t2 == a[i + 1] + t - a[i + 2]) {
					val = a[i + 1] + t;
				} else {
					val = a[i + 1] - t;
				}
			}
		}
		// cout << i << ' ' << val << ' ' << (a[i + 2] > a[i + 1]) << '\n';
		p[val] = i;
		a[i] = val;
	}
	mx = 1;
	for(int i = p[1] + 1;i < p[n];i++) {
		int val, T;
		T = query(p[1],i);	
		if(T != mx - 1) {
			val = mx = 1 + T;
		} else {
			int t2, t1;
			t2 = query(i - 2,i);
			t1 = query(i - 2,i - 1);
			int t = query(i - 1,i);
			if(a[i - 2] > a[i - 1]) {
				if(t2 == a[i - 2] - (a[i - 1] - t)) {
					val = a[i - 1] - t;
				} else {
					val = a[i - 1] + t;
				}
			} else {
				if(t2 == a[i - 1] + t - a[i - 2]) {
					val = a[i - 1] + t;
				} else {
					val = a[i - 1] - t;
				}
			}
		}
		// cout << i << ' ' << val << '\n';
		p[val] = i;
		a[i] = val;
	}
	int mn = n;
	for(int i = p[n] + 1;i <= n;i++) {
		int val, T = query(p[n],i);
		if(T != n - mn) {
			mn = val = n - T;
		} else {
			int t2, t1;
			t2 = query(i - 2,i);
			t1 = query(i - 2,i - 1);
			int t = query(i - 1,i);
			if(a[i - 2] > a[i - 1]) {
				if(t2 == a[i - 2] - (a[i - 1] - t)) {
					val = a[i - 1] - t;
				} else {
					val = a[i - 1] + t;
				}
			} else {
				if(t2 == a[i - 1] + t - a[i - 2]) {
					val = a[i - 1] + t;
				} else {
					val = a[i - 1] - t;
				}
			}
		}
		p[val] = i;
		a[i] = val;
	}
	for(int i = 1;i <= n;i++) {
		answer(p[i],i);
	}
}

Compilation message

xylophone.cpp: In function 'void solve(int)':
xylophone.cpp:38:12: warning: variable 't1' set but not used [-Wunused-but-set-variable]
   38 |    int t2, t1;
      |            ^~
xylophone.cpp:67:12: warning: variable 't1' set but not used [-Wunused-but-set-variable]
   67 |    int t2, t1;
      |            ^~
xylophone.cpp:95:12: warning: variable 't1' set but not used [-Wunused-but-set-variable]
   95 |    int t2, t1;
      |            ^~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Correct 3 ms 344 KB Output is correct
5 Correct 2 ms 344 KB Output is correct
6 Correct 2 ms 344 KB Output is correct
7 Correct 3 ms 344 KB Output is correct
8 Correct 2 ms 344 KB Output is correct
9 Correct 1 ms 344 KB Output is correct
10 Correct 1 ms 596 KB Output is correct
11 Correct 3 ms 344 KB Output is correct
12 Correct 3 ms 344 KB Output is correct
13 Correct 2 ms 344 KB Output is correct
14 Correct 4 ms 344 KB Output is correct
15 Correct 2 ms 344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Correct 3 ms 344 KB Output is correct
5 Correct 2 ms 344 KB Output is correct
6 Correct 2 ms 344 KB Output is correct
7 Correct 3 ms 344 KB Output is correct
8 Correct 2 ms 344 KB Output is correct
9 Correct 1 ms 344 KB Output is correct
10 Correct 1 ms 596 KB Output is correct
11 Correct 3 ms 344 KB Output is correct
12 Correct 3 ms 344 KB Output is correct
13 Correct 2 ms 344 KB Output is correct
14 Correct 4 ms 344 KB Output is correct
15 Correct 2 ms 344 KB Output is correct
16 Correct 6 ms 344 KB Output is correct
17 Correct 12 ms 344 KB Output is correct
18 Correct 16 ms 340 KB Output is correct
19 Correct 28 ms 448 KB Output is correct
20 Correct 26 ms 344 KB Output is correct
21 Correct 21 ms 596 KB Output is correct
22 Correct 21 ms 452 KB Output is correct
23 Correct 7 ms 476 KB Output is correct
24 Correct 19 ms 344 KB Output is correct
25 Correct 23 ms 344 KB Output is correct
26 Correct 23 ms 344 KB Output is correct
27 Correct 20 ms 452 KB Output is correct
28 Correct 21 ms 456 KB Output is correct
29 Correct 22 ms 456 KB Output is correct
30 Correct 23 ms 344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Correct 3 ms 344 KB Output is correct
5 Correct 2 ms 344 KB Output is correct
6 Correct 2 ms 344 KB Output is correct
7 Correct 3 ms 344 KB Output is correct
8 Correct 2 ms 344 KB Output is correct
9 Correct 1 ms 344 KB Output is correct
10 Correct 1 ms 596 KB Output is correct
11 Correct 3 ms 344 KB Output is correct
12 Correct 3 ms 344 KB Output is correct
13 Correct 2 ms 344 KB Output is correct
14 Correct 4 ms 344 KB Output is correct
15 Correct 2 ms 344 KB Output is correct
16 Correct 6 ms 344 KB Output is correct
17 Correct 12 ms 344 KB Output is correct
18 Correct 16 ms 340 KB Output is correct
19 Correct 28 ms 448 KB Output is correct
20 Correct 26 ms 344 KB Output is correct
21 Correct 21 ms 596 KB Output is correct
22 Correct 21 ms 452 KB Output is correct
23 Correct 7 ms 476 KB Output is correct
24 Correct 19 ms 344 KB Output is correct
25 Correct 23 ms 344 KB Output is correct
26 Correct 23 ms 344 KB Output is correct
27 Correct 20 ms 452 KB Output is correct
28 Correct 21 ms 456 KB Output is correct
29 Correct 22 ms 456 KB Output is correct
30 Correct 23 ms 344 KB Output is correct
31 Correct 49 ms 456 KB Output is correct
32 Incorrect 58 ms 344 KB Wrong Answer [2]
33 Halted 0 ms 0 KB -