Submission #996105

# Submission time Handle Problem Language Result Execution time Memory
996105 2024-06-10T08:04:11 Z anHiep Xylophone (JOI18_xylophone) C++17
47 / 100
2000 ms 97416 KB
#include "xylophone.h"
#include<bits/stdc++.h>

using namespace std;

static int a[5005];
static int d[5005][5005]; 

void solve(int n) {
	int dis = query(1, 2);
    for(int i=3; i<=n; i++) {
        d[i - 2][i] = query(i - 2, i);
        d[i - 1][i] = query(i - 1, i);
    }
    for(int i=1; i<=n; i++) {
        a[1] = i;
        for(int k=-1; k<=1; k+=2) {
            set<int> s;
            a[2] = a[1] + k*dis;
            s.insert(a[1]);
            s.insert(a[2]);
            for(int j=3; j<=n; j++) {
                int cal = max(a[j - 1], a[j - 2]) - min(a[j - 1], a[j - 2]);
                if(d[j - 2][j] == cal) {
                    if(a[j - 1] > a[j - 2]) a[j] = a[j - 1] - d[j - 1][j];
                    else a[j] = a[j - 1] + d[j - 1][j];
                }
                else {
                    if(a[j - 1] + d[j - 1][j] - min(a[j - 2], a[j - 1]) == d[j - 2][j]) a[j] = a[j - 1] + d[j - 1][j];
                    if(max(a[j - 2], a[j - 1]) - (a[j - 1] - d[j - 1][j]) == d[j - 2][j]) a[j] = a[j - 1] - d[j - 1][j];
                }
                s.insert(a[j]);
            }
            // if(a[1] == 9 && a[2] == 6) {
            //     cout<<(s.size() == n && *s.begin() == 1 && *s.rbegin() == n)<<'\n';
            // }
            if(s.size() == n && *s.begin() == 1 && *s.rbegin() == n) {
                int p1, pn;
                for(int j=1; j<=n; j++) {
                    if(a[j] == 1) p1 = j;
                    if(a[j] == n) pn = j;
                } 
                if(p1 < pn) {
                    for(int j=1; j<=n; j++) answer(j, a[j]);
                    return;
                }
            }
        }
    }
}

Compilation message

xylophone.cpp: In function 'void solve(int)':
xylophone.cpp:37:25: warning: comparison of integer expressions of different signedness: 'std::set<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   37 |             if(s.size() == n && *s.begin() == 1 && *s.rbegin() == n) {
      |                ~~~~~~~~~^~~~
xylophone.cpp:43:17: warning: 'pn' may be used uninitialized in this function [-Wmaybe-uninitialized]
   43 |                 if(p1 < pn) {
      |                 ^~
xylophone.cpp:43:17: warning: 'p1' 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 1 ms 344 KB Output is correct
3 Correct 1 ms 2392 KB Output is correct
4 Correct 2 ms 2392 KB Output is correct
5 Correct 2 ms 2392 KB Output is correct
6 Correct 2 ms 2392 KB Output is correct
7 Correct 2 ms 2392 KB Output is correct
8 Correct 2 ms 2392 KB Output is correct
9 Correct 1 ms 2528 KB Output is correct
10 Correct 2 ms 2392 KB Output is correct
11 Correct 1 ms 2528 KB Output is correct
12 Correct 1 ms 2392 KB Output is correct
13 Correct 2 ms 2648 KB Output is correct
14 Correct 1 ms 2528 KB Output is correct
15 Correct 1 ms 2392 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 1 ms 2392 KB Output is correct
4 Correct 2 ms 2392 KB Output is correct
5 Correct 2 ms 2392 KB Output is correct
6 Correct 2 ms 2392 KB Output is correct
7 Correct 2 ms 2392 KB Output is correct
8 Correct 2 ms 2392 KB Output is correct
9 Correct 1 ms 2528 KB Output is correct
10 Correct 2 ms 2392 KB Output is correct
11 Correct 1 ms 2528 KB Output is correct
12 Correct 1 ms 2392 KB Output is correct
13 Correct 2 ms 2648 KB Output is correct
14 Correct 1 ms 2528 KB Output is correct
15 Correct 1 ms 2392 KB Output is correct
16 Correct 4 ms 6488 KB Output is correct
17 Correct 16 ms 10584 KB Output is correct
18 Correct 28 ms 16928 KB Output is correct
19 Correct 83 ms 20824 KB Output is correct
20 Correct 104 ms 20824 KB Output is correct
21 Correct 114 ms 20824 KB Output is correct
22 Correct 106 ms 21352 KB Output is correct
23 Correct 12 ms 20816 KB Output is correct
24 Correct 57 ms 20816 KB Output is correct
25 Correct 12 ms 20816 KB Output is correct
26 Correct 95 ms 21092 KB Output is correct
27 Correct 52 ms 20824 KB Output is correct
28 Correct 27 ms 20816 KB Output is correct
29 Correct 102 ms 20960 KB Output is correct
30 Correct 33 ms 21240 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 1 ms 2392 KB Output is correct
4 Correct 2 ms 2392 KB Output is correct
5 Correct 2 ms 2392 KB Output is correct
6 Correct 2 ms 2392 KB Output is correct
7 Correct 2 ms 2392 KB Output is correct
8 Correct 2 ms 2392 KB Output is correct
9 Correct 1 ms 2528 KB Output is correct
10 Correct 2 ms 2392 KB Output is correct
11 Correct 1 ms 2528 KB Output is correct
12 Correct 1 ms 2392 KB Output is correct
13 Correct 2 ms 2648 KB Output is correct
14 Correct 1 ms 2528 KB Output is correct
15 Correct 1 ms 2392 KB Output is correct
16 Correct 4 ms 6488 KB Output is correct
17 Correct 16 ms 10584 KB Output is correct
18 Correct 28 ms 16928 KB Output is correct
19 Correct 83 ms 20824 KB Output is correct
20 Correct 104 ms 20824 KB Output is correct
21 Correct 114 ms 20824 KB Output is correct
22 Correct 106 ms 21352 KB Output is correct
23 Correct 12 ms 20816 KB Output is correct
24 Correct 57 ms 20816 KB Output is correct
25 Correct 12 ms 20816 KB Output is correct
26 Correct 95 ms 21092 KB Output is correct
27 Correct 52 ms 20824 KB Output is correct
28 Correct 27 ms 20816 KB Output is correct
29 Correct 102 ms 20960 KB Output is correct
30 Correct 33 ms 21240 KB Output is correct
31 Correct 255 ms 43600 KB Output is correct
32 Correct 1722 ms 62172 KB Output is correct
33 Correct 1586 ms 87076 KB Output is correct
34 Execution timed out 2972 ms 97416 KB Time limit exceeded
35 Halted 0 ms 0 KB -