Submission #702889

# Submission time Handle Problem Language Result Execution time Memory
702889 2023-02-25T09:29:13 Z hmm789 Xylophone (JOI18_xylophone) C++14
47 / 100
71 ms 304 KB
#include "xylophone.h"

static int A[5000];

void solve(int n) {
	int a[n], ans[n+1];
	for(int i = 1; i < n; i++) a[i] = query(i, i+1);
	int l = 1, r = n;
	while(l < r) {
		int m = (l+r)/2;
		if(query(m, n) == n-1) l = m+1;
		else r = m;
	}
	ans[l-1] = 1;
	ans[l] = a[l-1]+1;
	for(int i = l+1; i <= n; i++) {
		int tmp = query(i-2, i);
		//~ printf("a %d %d %d %d %d\n", i, tmp, a[i-1], ans[i-2], ans[i-1]);
		if(tmp == a[i-1] && ans[i-2] > ans[i-1] || tmp > a[i-1] && tmp != a[i-2] && ans[i-2] < ans[i-1] || tmp > a[i-1] && tmp == a[i-2] && ans[i-2] > ans[i-1]) {
			ans[i] = ans[i-1]+a[i-1];
			//~ printf("b");
		}
		else {
			ans[i] = ans[i-1]-a[i-1];
			//~ printf("c");
		}
	}
	for(int i = l-2; i >= 1; i--) {
		int tmp = query(i, i+2);
		if(tmp == a[i] && ans[i+2] > ans[i+1] || tmp > a[i] && tmp != a[i+1] && ans[i+2] < ans[i+1] || tmp > a[i] && tmp == a[i+1] && ans[i+2] > ans[i+1]) ans[i] = ans[i+1]+a[i];
		else ans[i] = ans[i+1]-a[i];
	}
	//~ printf("%d\n", l);
	//~ for(int i = 1; i <= n; i++) printf("%d ", ans[i]);
	//~ printf("\n");
	for(int i = 1; i <= n; i++) answer(i, ans[i]);
}

Compilation message

xylophone.cpp: In function 'void solve(int)':
xylophone.cpp:19:20: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
   19 |   if(tmp == a[i-1] && ans[i-2] > ans[i-1] || tmp > a[i-1] && tmp != a[i-2] && ans[i-2] < ans[i-1] || tmp > a[i-1] && tmp == a[i-2] && ans[i-2] > ans[i-1]) {
      |      ~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
xylophone.cpp:19:132: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
   19 |   if(tmp == a[i-1] && ans[i-2] > ans[i-1] || tmp > a[i-1] && tmp != a[i-2] && ans[i-2] < ans[i-1] || tmp > a[i-1] && tmp == a[i-2] && ans[i-2] > ans[i-1]) {
      |                                                                                                      ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
xylophone.cpp:30:18: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
   30 |   if(tmp == a[i] && ans[i+2] > ans[i+1] || tmp > a[i] && tmp != a[i+1] && ans[i+2] < ans[i+1] || tmp > a[i] && tmp == a[i+1] && ans[i+2] > ans[i+1]) ans[i] = ans[i+1]+a[i];
      |      ~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
xylophone.cpp:30:126: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
   30 |   if(tmp == a[i] && ans[i+2] > ans[i+1] || tmp > a[i] && tmp != a[i+1] && ans[i+2] < ans[i+1] || tmp > a[i] && tmp == a[i+1] && ans[i+2] > ans[i+1]) ans[i] = ans[i+1]+a[i];
      |                                                                                                  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
xylophone.cpp: At global scope:
xylophone.cpp:3:12: warning: 'A' defined but not used [-Wunused-variable]
    3 | static int A[5000];
      |            ^
# 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 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 1 ms 208 KB Output is correct
13 Correct 2 ms 208 KB Output is correct
14 Correct 2 ms 208 KB Output is correct
15 Correct 3 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 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 1 ms 208 KB Output is correct
13 Correct 2 ms 208 KB Output is correct
14 Correct 2 ms 208 KB Output is correct
15 Correct 3 ms 208 KB Output is correct
16 Correct 4 ms 208 KB Output is correct
17 Correct 6 ms 208 KB Output is correct
18 Correct 15 ms 208 KB Output is correct
19 Correct 19 ms 208 KB Output is correct
20 Correct 15 ms 268 KB Output is correct
21 Correct 19 ms 272 KB Output is correct
22 Correct 15 ms 208 KB Output is correct
23 Correct 17 ms 304 KB Output is correct
24 Correct 19 ms 268 KB Output is correct
25 Correct 15 ms 268 KB Output is correct
26 Correct 28 ms 208 KB Output is correct
27 Correct 9 ms 292 KB Output is correct
28 Correct 17 ms 280 KB Output is correct
29 Correct 15 ms 208 KB Output is correct
30 Correct 12 ms 272 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 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 1 ms 208 KB Output is correct
13 Correct 2 ms 208 KB Output is correct
14 Correct 2 ms 208 KB Output is correct
15 Correct 3 ms 208 KB Output is correct
16 Correct 4 ms 208 KB Output is correct
17 Correct 6 ms 208 KB Output is correct
18 Correct 15 ms 208 KB Output is correct
19 Correct 19 ms 208 KB Output is correct
20 Correct 15 ms 268 KB Output is correct
21 Correct 19 ms 272 KB Output is correct
22 Correct 15 ms 208 KB Output is correct
23 Correct 17 ms 304 KB Output is correct
24 Correct 19 ms 268 KB Output is correct
25 Correct 15 ms 268 KB Output is correct
26 Correct 28 ms 208 KB Output is correct
27 Correct 9 ms 292 KB Output is correct
28 Correct 17 ms 280 KB Output is correct
29 Correct 15 ms 208 KB Output is correct
30 Correct 12 ms 272 KB Output is correct
31 Correct 42 ms 280 KB Output is correct
32 Correct 39 ms 208 KB Output is correct
33 Correct 62 ms 300 KB Output is correct
34 Incorrect 71 ms 208 KB Wrong Answer [2]
35 Halted 0 ms 0 KB -