Submission #702858

# Submission time Handle Problem Language Result Execution time Memory
702858 2023-02-25T09:10:01 Z hmm789 Xylophone (JOI18_xylophone) C++14
0 / 100
0 ms 208 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);
		if(tmp < ans[i-1] && ans[i-2] > ans[i-1] || tmp > ans[i-1] && ans[i-2] < ans[i-1]) ans[i] = ans[i-1]+a[i-1];
		else ans[i] = ans[i-1]-a[i-1];
	}
	for(int i = l-2; i >= 0; i--) {
		int tmp = query(i, i+2);
		if(tmp < ans[i+1] && ans[i+2] > ans[i+1] || tmp > ans[i+1] && ans[i+2] < ans[i+1]) ans[i] = ans[i+1]+a[i+1];
		else ans[i] = ans[i+1]-a[i+1];
	}
	for(int i = 1; i <= n; i++) answer(i, ans[i]);
}

Compilation message

xylophone.cpp: In function 'void solve(int)':
xylophone.cpp:18:21: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
   18 |   if(tmp < ans[i-1] && ans[i-2] > ans[i-1] || tmp > ans[i-1] && ans[i-2] < ans[i-1]) ans[i] = ans[i-1]+a[i-1];
      |      ~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
xylophone.cpp:23:21: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
   23 |   if(tmp < ans[i+1] && ans[i+2] > ans[i+1] || tmp > ans[i+1] && ans[i+2] < ans[i+1]) ans[i] = ans[i+1]+a[i+1];
      |      ~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
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 Incorrect 0 ms 208 KB Wrong Answer [1]
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 208 KB Wrong Answer [1]
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 208 KB Wrong Answer [1]
2 Halted 0 ms 0 KB -