Submission #346586

# Submission time Handle Problem Language Result Execution time Memory
346586 2021-01-10T09:01:10 Z jamezzz Xylophone (JOI18_xylophone) C++14
100 / 100
129 ms 652 KB
#include "xylophone.h"
#include <bits/stdc++.h>
using namespace std;

//static int A[5000];

void solve(int N) {
    int ans[N + 5], val[N + 5];
    val[1] = 0;
    val[2] = query(1, 2);
    for (int i = 3; i <= N; ++i){
        int tmp = query(i - 1, i);
        int pv = val[i - 1] - val[i - 2];
        if (query(i - 2, i) == abs(pv) + tmp){
            if (pv < 0) val[i] = val[i - 1] - tmp;
            else val[i] = val[i - 1] + tmp;
        }
        else{
            if (pv < 0) val[i] = val[i - 1] + tmp;
            else val[i] = val[i - 1] - tmp;
        }
    }
    int mn = N + 1, mx = - N - 1, mnid = 0, mxid = 0;
    for (int i = 1; i <= N; ++i){
        if (val[i] < mn){
            mn = val[i]; mnid = i;
        }
        if (val[i] > mx){
            mx = val[i]; mxid = i;
        }
    }
    if (mnid > mxid){
        for (int i = 1; i <= N; ++i){
            val[i] = -val[i];
        }
        mn = -mx;
    }
    for (int i = 1; i <= N; ++i){
        answer(i, val[i] - mn + 1);
    }
}

Compilation message

xylophone.cpp: In function 'void solve(int)':
xylophone.cpp:8:9: warning: unused variable 'ans' [-Wunused-variable]
    8 |     int ans[N + 5], val[N + 5];
      |         ^~~
# 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 1 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 2 ms 364 KB Output is correct
7 Correct 3 ms 364 KB Output is correct
8 Correct 3 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 2 ms 384 KB Output is correct
12 Correct 3 ms 364 KB Output is correct
13 Correct 3 ms 364 KB Output is correct
14 Correct 2 ms 364 KB Output is correct
15 Correct 2 ms 384 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 1 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 2 ms 364 KB Output is correct
7 Correct 3 ms 364 KB Output is correct
8 Correct 3 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 2 ms 384 KB Output is correct
12 Correct 3 ms 364 KB Output is correct
13 Correct 3 ms 364 KB Output is correct
14 Correct 2 ms 364 KB Output is correct
15 Correct 2 ms 384 KB Output is correct
16 Correct 5 ms 364 KB Output is correct
17 Correct 11 ms 364 KB Output is correct
18 Correct 17 ms 364 KB Output is correct
19 Correct 14 ms 376 KB Output is correct
20 Correct 22 ms 364 KB Output is correct
21 Correct 19 ms 364 KB Output is correct
22 Correct 20 ms 364 KB Output is correct
23 Correct 17 ms 364 KB Output is correct
24 Correct 25 ms 364 KB Output is correct
25 Correct 24 ms 492 KB Output is correct
26 Correct 23 ms 364 KB Output is correct
27 Correct 17 ms 364 KB Output is correct
28 Correct 21 ms 364 KB Output is correct
29 Correct 20 ms 364 KB Output is correct
30 Correct 25 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 1 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 2 ms 364 KB Output is correct
7 Correct 3 ms 364 KB Output is correct
8 Correct 3 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 2 ms 384 KB Output is correct
12 Correct 3 ms 364 KB Output is correct
13 Correct 3 ms 364 KB Output is correct
14 Correct 2 ms 364 KB Output is correct
15 Correct 2 ms 384 KB Output is correct
16 Correct 5 ms 364 KB Output is correct
17 Correct 11 ms 364 KB Output is correct
18 Correct 17 ms 364 KB Output is correct
19 Correct 14 ms 376 KB Output is correct
20 Correct 22 ms 364 KB Output is correct
21 Correct 19 ms 364 KB Output is correct
22 Correct 20 ms 364 KB Output is correct
23 Correct 17 ms 364 KB Output is correct
24 Correct 25 ms 364 KB Output is correct
25 Correct 24 ms 492 KB Output is correct
26 Correct 23 ms 364 KB Output is correct
27 Correct 17 ms 364 KB Output is correct
28 Correct 21 ms 364 KB Output is correct
29 Correct 20 ms 364 KB Output is correct
30 Correct 25 ms 364 KB Output is correct
31 Correct 48 ms 492 KB Output is correct
32 Correct 65 ms 384 KB Output is correct
33 Correct 100 ms 652 KB Output is correct
34 Correct 85 ms 504 KB Output is correct
35 Correct 86 ms 392 KB Output is correct
36 Correct 117 ms 364 KB Output is correct
37 Correct 98 ms 492 KB Output is correct
38 Correct 129 ms 364 KB Output is correct
39 Correct 119 ms 364 KB Output is correct
40 Correct 70 ms 492 KB Output is correct
41 Correct 74 ms 492 KB Output is correct
42 Correct 96 ms 604 KB Output is correct
43 Correct 101 ms 636 KB Output is correct
44 Correct 68 ms 364 KB Output is correct
45 Correct 84 ms 364 KB Output is correct
46 Correct 92 ms 492 KB Output is correct
47 Correct 74 ms 364 KB Output is correct
48 Correct 84 ms 492 KB Output is correct
49 Correct 72 ms 620 KB Output is correct
50 Correct 82 ms 364 KB Output is correct
51 Correct 86 ms 364 KB Output is correct
52 Correct 92 ms 364 KB Output is correct
53 Correct 95 ms 392 KB Output is correct
54 Correct 87 ms 364 KB Output is correct
55 Correct 75 ms 380 KB Output is correct
56 Correct 87 ms 364 KB Output is correct
57 Correct 118 ms 364 KB Output is correct
58 Correct 107 ms 492 KB Output is correct
59 Correct 68 ms 444 KB Output is correct
60 Correct 99 ms 364 KB Output is correct