Submission #857531

# Submission time Handle Problem Language Result Execution time Memory
857531 2023-10-06T10:49:40 Z Trisanu_Das Xylophone (JOI18_xylophone) C++17
100 / 100
61 ms 1200 KB
#include "xylophone.h"
#include <bits/stdc++.h>
using namespace std;
 
int a[5001];
 
void solve(int n) {
	a[1] = 0;
	a[2] = query(1, 2);
	for(int i = 2; i < n; i++){
		int x = query(i, i + 1), y = query(i - 1, i + 1);
		a[i + 1] = a[i] + x * (a[i] - a[i - 1] < 0 ? 1 : -1) * (y == x + abs(a[i] - a[i - 1]) ? -1 : 1);
	}
	int mn = *min_element(a + 1, a + n + 1);
	int u, v;
	for(int i = 1; i <= n; ++i){
		a[i] -= mn;
		if(a[i] == 0) u = i;
		if(a[i] == n - 1) v = i;
	}
	bool flag = u < v;
	for(int i = 1; i <= n; ++i) answer(i, flag ? a[i] + 1 : n - a[i]);
}

Compilation message

xylophone.cpp: In function 'void solve(int)':
xylophone.cpp:22:36: warning: 'v' may be used uninitialized in this function [-Wmaybe-uninitialized]
   22 |  for(int i = 1; i <= n; ++i) answer(i, flag ? a[i] + 1 : n - a[i]);
      |                              ~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
xylophone.cpp:22:36: warning: 'u' may be used uninitialized in this function [-Wmaybe-uninitialized]
# 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 388 KB Output is correct
4 Correct 2 ms 344 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
6 Correct 1 ms 344 KB Output is correct
7 Correct 1 ms 344 KB Output is correct
8 Correct 1 ms 344 KB Output is correct
9 Correct 1 ms 344 KB Output is correct
10 Correct 1 ms 344 KB Output is correct
11 Correct 1 ms 344 KB Output is correct
12 Correct 1 ms 344 KB Output is correct
13 Correct 1 ms 344 KB Output is correct
14 Correct 1 ms 344 KB Output is correct
15 Correct 1 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 388 KB Output is correct
4 Correct 2 ms 344 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
6 Correct 1 ms 344 KB Output is correct
7 Correct 1 ms 344 KB Output is correct
8 Correct 1 ms 344 KB Output is correct
9 Correct 1 ms 344 KB Output is correct
10 Correct 1 ms 344 KB Output is correct
11 Correct 1 ms 344 KB Output is correct
12 Correct 1 ms 344 KB Output is correct
13 Correct 1 ms 344 KB Output is correct
14 Correct 1 ms 344 KB Output is correct
15 Correct 1 ms 344 KB Output is correct
16 Correct 2 ms 344 KB Output is correct
17 Correct 3 ms 444 KB Output is correct
18 Correct 8 ms 600 KB Output is correct
19 Correct 11 ms 436 KB Output is correct
20 Correct 11 ms 440 KB Output is correct
21 Correct 10 ms 504 KB Output is correct
22 Correct 10 ms 940 KB Output is correct
23 Correct 11 ms 696 KB Output is correct
24 Correct 8 ms 440 KB Output is correct
25 Correct 8 ms 436 KB Output is correct
26 Correct 9 ms 436 KB Output is correct
27 Correct 9 ms 440 KB Output is correct
28 Correct 10 ms 436 KB Output is correct
29 Correct 10 ms 700 KB Output is correct
30 Correct 10 ms 444 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 388 KB Output is correct
4 Correct 2 ms 344 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
6 Correct 1 ms 344 KB Output is correct
7 Correct 1 ms 344 KB Output is correct
8 Correct 1 ms 344 KB Output is correct
9 Correct 1 ms 344 KB Output is correct
10 Correct 1 ms 344 KB Output is correct
11 Correct 1 ms 344 KB Output is correct
12 Correct 1 ms 344 KB Output is correct
13 Correct 1 ms 344 KB Output is correct
14 Correct 1 ms 344 KB Output is correct
15 Correct 1 ms 344 KB Output is correct
16 Correct 2 ms 344 KB Output is correct
17 Correct 3 ms 444 KB Output is correct
18 Correct 8 ms 600 KB Output is correct
19 Correct 11 ms 436 KB Output is correct
20 Correct 11 ms 440 KB Output is correct
21 Correct 10 ms 504 KB Output is correct
22 Correct 10 ms 940 KB Output is correct
23 Correct 11 ms 696 KB Output is correct
24 Correct 8 ms 440 KB Output is correct
25 Correct 8 ms 436 KB Output is correct
26 Correct 9 ms 436 KB Output is correct
27 Correct 9 ms 440 KB Output is correct
28 Correct 10 ms 436 KB Output is correct
29 Correct 10 ms 700 KB Output is correct
30 Correct 10 ms 444 KB Output is correct
31 Correct 20 ms 452 KB Output is correct
32 Correct 31 ms 452 KB Output is correct
33 Correct 38 ms 704 KB Output is correct
34 Correct 54 ms 696 KB Output is correct
35 Correct 52 ms 440 KB Output is correct
36 Correct 44 ms 672 KB Output is correct
37 Correct 49 ms 676 KB Output is correct
38 Correct 39 ms 440 KB Output is correct
39 Correct 61 ms 688 KB Output is correct
40 Correct 52 ms 680 KB Output is correct
41 Correct 47 ms 684 KB Output is correct
42 Correct 38 ms 936 KB Output is correct
43 Correct 46 ms 440 KB Output is correct
44 Correct 46 ms 436 KB Output is correct
45 Correct 46 ms 1200 KB Output is correct
46 Correct 52 ms 1184 KB Output is correct
47 Correct 46 ms 696 KB Output is correct
48 Correct 58 ms 684 KB Output is correct
49 Correct 46 ms 1196 KB Output is correct
50 Correct 50 ms 680 KB Output is correct
51 Correct 55 ms 684 KB Output is correct
52 Correct 47 ms 688 KB Output is correct
53 Correct 46 ms 680 KB Output is correct
54 Correct 49 ms 688 KB Output is correct
55 Correct 57 ms 440 KB Output is correct
56 Correct 47 ms 440 KB Output is correct
57 Correct 50 ms 440 KB Output is correct
58 Correct 49 ms 676 KB Output is correct
59 Correct 54 ms 448 KB Output is correct
60 Correct 51 ms 680 KB Output is correct