Submission #232012

# Submission time Handle Problem Language Result Execution time Memory
232012 2020-05-15T17:17:31 Z alexandra_udristoiu Xylophone (JOI18_xylophone) C++14
100 / 100
73 ms 632 KB
#include<iostream>
#include "xylophone.h"
using namespace std;
static int v[5005], viz[5005], dif[5005];

void solve(int n) {
    int i, st, dr, mid, d, d3, p;
    st = 1;
    dr = n;
    while(st <= dr){
        mid = (st + dr) / 2;
        if(query(mid, n) == n - 1){
            st = mid + 1;
        }
        else{
            dr = mid - 1;
        }
    }
    p = dr;
    v[p] = viz[1] = 1;
    for(i = p - 1; i >= 1; i--){
        d = query(i, i + 1);
        if(v[i + 1] - d < 1 || viz[ v[i + 1] - d ] == 1){
            v[i] = v[i + 1] + d;
        }
        else{
            if(v[i + 1] + d > n || viz[ v[i + 1] + d ] == 1){
                v[i] = v[i + 1] - d;
            }
            else{
                d3 = query(i, i + 2);
                if(d3 == d + dif[i + 1]){
                    if(v[i + 2] > v[i + 1]){
                        v[i] = v[i + 1] - d;
                    }
                    else{
                        v[i] = v[i + 1] + d;
                    }
                }
                else{
                    if(v[i + 2] < v[i + 1]){
                        v[i] = v[i + 1] - d;
                    }
                    else{
                        v[i] = v[i + 1] + d;
                    }
                }
            }
        }
        dif[i] = d;
        viz[ v[i] ] = 1;
    }
    for(i = p + 1; i <= n; i++){
        d = query(i - 1, i);
        if(v[i - 1] - d < 1 || viz[ v[i - 1] - d ] == 1){
            v[i] = v[i - 1] + d;
        }
        else{
            if(v[i - 1] + d > n || viz[ v[i - 1] + d ] == 1){
                v[i] = v[i - 1] - d;
            }
            else{
                d3 = query(i - 2, i);
                if(d3 == d + dif[i - 1]){
                    if(v[i - 2] > v[i - 1]){
                        v[i] = v[i - 1] - d;
                    }
                    else{
                        v[i] = v[i - 1] + d;
                    }
                }
                else{
                    if(v[i - 2] < v[i - 1]){
                        v[i] = v[i - 1] - d;
                    }
                    else{
                        v[i] = v[i - 1] + d;
                    }
                }
            }
        }
        dif[i] = d;
        viz[ v[i] ] = 1;
    }
    for(i = 1; i <= n; i++){
        answer(i, v[i]);
    }
    return;
}
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 372 KB Output is correct
3 Correct 5 ms 256 KB Output is correct
4 Correct 6 ms 256 KB Output is correct
5 Correct 6 ms 256 KB Output is correct
6 Correct 6 ms 256 KB Output is correct
7 Correct 6 ms 256 KB Output is correct
8 Correct 6 ms 384 KB Output is correct
9 Correct 6 ms 256 KB Output is correct
10 Correct 5 ms 384 KB Output is correct
11 Correct 6 ms 384 KB Output is correct
12 Correct 5 ms 256 KB Output is correct
13 Correct 6 ms 384 KB Output is correct
14 Correct 6 ms 256 KB Output is correct
15 Correct 6 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 372 KB Output is correct
3 Correct 5 ms 256 KB Output is correct
4 Correct 6 ms 256 KB Output is correct
5 Correct 6 ms 256 KB Output is correct
6 Correct 6 ms 256 KB Output is correct
7 Correct 6 ms 256 KB Output is correct
8 Correct 6 ms 384 KB Output is correct
9 Correct 6 ms 256 KB Output is correct
10 Correct 5 ms 384 KB Output is correct
11 Correct 6 ms 384 KB Output is correct
12 Correct 5 ms 256 KB Output is correct
13 Correct 6 ms 384 KB Output is correct
14 Correct 6 ms 256 KB Output is correct
15 Correct 6 ms 384 KB Output is correct
16 Correct 7 ms 384 KB Output is correct
17 Correct 10 ms 384 KB Output is correct
18 Correct 15 ms 384 KB Output is correct
19 Correct 16 ms 384 KB Output is correct
20 Correct 18 ms 384 KB Output is correct
21 Correct 15 ms 384 KB Output is correct
22 Correct 15 ms 504 KB Output is correct
23 Correct 12 ms 384 KB Output is correct
24 Correct 12 ms 384 KB Output is correct
25 Correct 14 ms 384 KB Output is correct
26 Correct 17 ms 384 KB Output is correct
27 Correct 11 ms 376 KB Output is correct
28 Correct 18 ms 384 KB Output is correct
29 Correct 13 ms 384 KB Output is correct
30 Correct 18 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 372 KB Output is correct
3 Correct 5 ms 256 KB Output is correct
4 Correct 6 ms 256 KB Output is correct
5 Correct 6 ms 256 KB Output is correct
6 Correct 6 ms 256 KB Output is correct
7 Correct 6 ms 256 KB Output is correct
8 Correct 6 ms 384 KB Output is correct
9 Correct 6 ms 256 KB Output is correct
10 Correct 5 ms 384 KB Output is correct
11 Correct 6 ms 384 KB Output is correct
12 Correct 5 ms 256 KB Output is correct
13 Correct 6 ms 384 KB Output is correct
14 Correct 6 ms 256 KB Output is correct
15 Correct 6 ms 384 KB Output is correct
16 Correct 7 ms 384 KB Output is correct
17 Correct 10 ms 384 KB Output is correct
18 Correct 15 ms 384 KB Output is correct
19 Correct 16 ms 384 KB Output is correct
20 Correct 18 ms 384 KB Output is correct
21 Correct 15 ms 384 KB Output is correct
22 Correct 15 ms 504 KB Output is correct
23 Correct 12 ms 384 KB Output is correct
24 Correct 12 ms 384 KB Output is correct
25 Correct 14 ms 384 KB Output is correct
26 Correct 17 ms 384 KB Output is correct
27 Correct 11 ms 376 KB Output is correct
28 Correct 18 ms 384 KB Output is correct
29 Correct 13 ms 384 KB Output is correct
30 Correct 18 ms 384 KB Output is correct
31 Correct 29 ms 384 KB Output is correct
32 Correct 36 ms 404 KB Output is correct
33 Correct 51 ms 512 KB Output is correct
34 Correct 49 ms 536 KB Output is correct
35 Correct 62 ms 416 KB Output is correct
36 Correct 53 ms 384 KB Output is correct
37 Correct 53 ms 384 KB Output is correct
38 Correct 47 ms 384 KB Output is correct
39 Correct 62 ms 504 KB Output is correct
40 Correct 61 ms 384 KB Output is correct
41 Correct 55 ms 384 KB Output is correct
42 Correct 41 ms 384 KB Output is correct
43 Correct 47 ms 384 KB Output is correct
44 Correct 48 ms 384 KB Output is correct
45 Correct 66 ms 384 KB Output is correct
46 Correct 51 ms 540 KB Output is correct
47 Correct 58 ms 384 KB Output is correct
48 Correct 68 ms 444 KB Output is correct
49 Correct 65 ms 424 KB Output is correct
50 Correct 61 ms 384 KB Output is correct
51 Correct 58 ms 384 KB Output is correct
52 Correct 34 ms 372 KB Output is correct
53 Correct 63 ms 384 KB Output is correct
54 Correct 34 ms 376 KB Output is correct
55 Correct 73 ms 632 KB Output is correct
56 Correct 58 ms 384 KB Output is correct
57 Correct 57 ms 384 KB Output is correct
58 Correct 65 ms 384 KB Output is correct
59 Correct 52 ms 384 KB Output is correct
60 Correct 61 ms 504 KB Output is correct