Submission #321769

# Submission time Handle Problem Language Result Execution time Memory
321769 2020-11-13T10:19:52 Z lohacho Xylophone (JOI18_xylophone) C++14
100 / 100
149 ms 876 KB
#include "xylophone.h"
#include <bits/stdc++.h>

using namespace std;

using LL = long long;
const int MOD = (int)1e9 + 7;

int A[5004];
int val[5004][3];
int ans[5004];
map<int, int> chk;

void out(int N){
    for(int i = 1; i <= N; ++i){
        answer(i, ans[i]);
    }
}

void solve(int N) {
    for(int i = 1; i <= N; ++i){
        for(int j = i + 1; j <= min(N, i + 2); ++j){
            val[i][j - i] = query(i, j);
        }
    }
    ans[2] = val[1][1];
    int low = MOD;
    for(int i = 3; i <= N; ++i){
        int bu = (ans[i - 1] - ans[i - 2]) / abs(ans[i - 1] - ans[i - 2]);
        if(val[i - 2][1] + val[i - 1][1] != val[i - 2][2]){
            bu *= -1;
        }
        ans[i] = ans[i - 1] + val[i - 1][1] * bu;
    }
    for(int i = 1; i <= N; ++i){
        low = min(low, ans[i]);
    }
    int cf = 1;
    for(int i = 1; i <= N; ++i){
        ans[i] += -low + 1;
        if(ans[i] < 1 || ans[i] > N || chk[ans[i]]){
            cf = 0;
            break;
        }
        chk[ans[i]] = 1;
    }
    if(cf){
        for(int i = 1; i <= N; ++i){
            if(ans[i] == 1){
                out(N);
                return;
            }
            if(ans[i] == N){
                break;
            }
        }
    }
    ans[1] = 0;
    ans[2] = -val[1][1];
    low = MOD;
    for(int i = 3; i <= N; ++i){
        int bu = (ans[i - 1] - ans[i - 2]) / abs(ans[i - 1] - ans[i - 2]);
        if(val[i - 2][1] + val[i - 1][1] != val[i - 2][2]){
            bu *= -1;
        }
        ans[i] = ans[i - 1] + val[i - 1][1] * bu;
    }
    for(int i = 1; i <= N; ++i){
        low = min(low, ans[i]);
    }
    for(int i = 1; i <= N; ++i){
        ans[i] += -low + 1;
    }
    out(N);
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 2 ms 364 KB Output is correct
4 Correct 3 ms 364 KB Output is correct
5 Correct 3 ms 364 KB Output is correct
6 Correct 3 ms 364 KB Output is correct
7 Correct 2 ms 364 KB Output is correct
8 Correct 2 ms 364 KB Output is correct
9 Correct 3 ms 364 KB Output is correct
10 Correct 2 ms 364 KB Output is correct
11 Correct 3 ms 384 KB Output is correct
12 Correct 3 ms 364 KB Output is correct
13 Correct 3 ms 384 KB Output is correct
14 Correct 3 ms 364 KB Output is correct
15 Correct 3 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 2 ms 364 KB Output is correct
4 Correct 3 ms 364 KB Output is correct
5 Correct 3 ms 364 KB Output is correct
6 Correct 3 ms 364 KB Output is correct
7 Correct 2 ms 364 KB Output is correct
8 Correct 2 ms 364 KB Output is correct
9 Correct 3 ms 364 KB Output is correct
10 Correct 2 ms 364 KB Output is correct
11 Correct 3 ms 384 KB Output is correct
12 Correct 3 ms 364 KB Output is correct
13 Correct 3 ms 384 KB Output is correct
14 Correct 3 ms 364 KB Output is correct
15 Correct 3 ms 364 KB Output is correct
16 Correct 5 ms 364 KB Output is correct
17 Correct 11 ms 384 KB Output is correct
18 Correct 20 ms 364 KB Output is correct
19 Correct 19 ms 364 KB Output is correct
20 Correct 18 ms 364 KB Output is correct
21 Correct 19 ms 364 KB Output is correct
22 Correct 16 ms 492 KB Output is correct
23 Correct 21 ms 364 KB Output is correct
24 Correct 24 ms 364 KB Output is correct
25 Correct 19 ms 364 KB Output is correct
26 Correct 19 ms 364 KB Output is correct
27 Correct 20 ms 364 KB Output is correct
28 Correct 26 ms 364 KB Output is correct
29 Correct 26 ms 364 KB Output is correct
30 Correct 11 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 2 ms 364 KB Output is correct
4 Correct 3 ms 364 KB Output is correct
5 Correct 3 ms 364 KB Output is correct
6 Correct 3 ms 364 KB Output is correct
7 Correct 2 ms 364 KB Output is correct
8 Correct 2 ms 364 KB Output is correct
9 Correct 3 ms 364 KB Output is correct
10 Correct 2 ms 364 KB Output is correct
11 Correct 3 ms 384 KB Output is correct
12 Correct 3 ms 364 KB Output is correct
13 Correct 3 ms 384 KB Output is correct
14 Correct 3 ms 364 KB Output is correct
15 Correct 3 ms 364 KB Output is correct
16 Correct 5 ms 364 KB Output is correct
17 Correct 11 ms 384 KB Output is correct
18 Correct 20 ms 364 KB Output is correct
19 Correct 19 ms 364 KB Output is correct
20 Correct 18 ms 364 KB Output is correct
21 Correct 19 ms 364 KB Output is correct
22 Correct 16 ms 492 KB Output is correct
23 Correct 21 ms 364 KB Output is correct
24 Correct 24 ms 364 KB Output is correct
25 Correct 19 ms 364 KB Output is correct
26 Correct 19 ms 364 KB Output is correct
27 Correct 20 ms 364 KB Output is correct
28 Correct 26 ms 364 KB Output is correct
29 Correct 26 ms 364 KB Output is correct
30 Correct 11 ms 364 KB Output is correct
31 Correct 41 ms 492 KB Output is correct
32 Correct 56 ms 492 KB Output is correct
33 Correct 80 ms 620 KB Output is correct
34 Correct 81 ms 876 KB Output is correct
35 Correct 95 ms 620 KB Output is correct
36 Correct 112 ms 748 KB Output is correct
37 Correct 89 ms 620 KB Output is correct
38 Correct 129 ms 620 KB Output is correct
39 Correct 94 ms 620 KB Output is correct
40 Correct 118 ms 748 KB Output is correct
41 Correct 90 ms 620 KB Output is correct
42 Correct 111 ms 620 KB Output is correct
43 Correct 122 ms 748 KB Output is correct
44 Correct 60 ms 748 KB Output is correct
45 Correct 67 ms 780 KB Output is correct
46 Correct 90 ms 620 KB Output is correct
47 Correct 99 ms 620 KB Output is correct
48 Correct 70 ms 784 KB Output is correct
49 Correct 94 ms 620 KB Output is correct
50 Correct 95 ms 620 KB Output is correct
51 Correct 96 ms 620 KB Output is correct
52 Correct 82 ms 748 KB Output is correct
53 Correct 92 ms 784 KB Output is correct
54 Correct 149 ms 620 KB Output is correct
55 Correct 94 ms 620 KB Output is correct
56 Correct 96 ms 620 KB Output is correct
57 Correct 121 ms 620 KB Output is correct
58 Correct 123 ms 620 KB Output is correct
59 Correct 77 ms 620 KB Output is correct
60 Correct 114 ms 748 KB Output is correct