Submission #113300

# Submission time Handle Problem Language Result Execution time Memory
113300 2019-05-24T19:51:01 Z popovicirobert Xylophone (JOI18_xylophone) C++14
47 / 100
95 ms 408 KB
#include "xylophone.h"
#include <bits/stdc++.h>

using namespace std;

//static int A[5000];

int cnt = 0;

inline int get(int a, int b, int pa, int pb, int pc) {

    int bc = query(min(pb, pc), max(pb, pc)), ac = query(min(pa, pc), max(pa, pc));

    if(a < b) {
        if(bc == ac) {
            return b - bc;
        }
        if(ac == abs(a - b)) {
            return b - bc;
        }
        return b + bc;
    }
    else {
        if(bc == ac) {
            return b + bc;
        }
        if(ac == abs(a - b)) {
            return b + bc;
        }
        return b - bc;
    }
}

void solve(int n) {

    int pos = n + 1, i;

    for(int step = 1 << 15; step; step >>= 1) {
        if(pos - step >= 1 && query(pos - step, n) < n - 1) {
            pos -= step;
        }
    }

    pos--; // 1

    vector <int> sol(n + 2);

    sol[pos] = 1;

    if(pos > 1) {
        sol[pos - 1] = 1 + query(pos - 1, pos);
    }

    int a = sol[pos], b = sol[pos - 1];

    for(i = pos - 2; i >= 1; i--) {
        int c = get(a, b, i + 2, i + 1, i);
        sol[i] = c;
        a = b;
        b = c;
    }

    if(pos < n) {
        sol[pos + 1] = 1 + query(pos, pos + 1);
    }

    a = sol[pos], b = sol[pos + 1];

    for(i = pos + 2; i <= n; i++) {
        int c = get(a, b, i - 2, i - 1, i);
        sol[i] = c;
        a = b;
        b = c;
    }

    for(i = 1; i <= n; i++) {
        answer(i, sol[i]);
    }

}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 3 ms 384 KB Output is correct
3 Correct 2 ms 256 KB Output is correct
4 Correct 3 ms 384 KB Output is correct
5 Correct 4 ms 384 KB Output is correct
6 Correct 4 ms 384 KB Output is correct
7 Correct 4 ms 256 KB Output is correct
8 Correct 2 ms 384 KB Output is correct
9 Correct 4 ms 380 KB Output is correct
10 Correct 3 ms 256 KB Output is correct
11 Correct 3 ms 256 KB Output is correct
12 Correct 3 ms 256 KB Output is correct
13 Correct 4 ms 256 KB Output is correct
14 Correct 3 ms 384 KB Output is correct
15 Correct 4 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 3 ms 384 KB Output is correct
3 Correct 2 ms 256 KB Output is correct
4 Correct 3 ms 384 KB Output is correct
5 Correct 4 ms 384 KB Output is correct
6 Correct 4 ms 384 KB Output is correct
7 Correct 4 ms 256 KB Output is correct
8 Correct 2 ms 384 KB Output is correct
9 Correct 4 ms 380 KB Output is correct
10 Correct 3 ms 256 KB Output is correct
11 Correct 3 ms 256 KB Output is correct
12 Correct 3 ms 256 KB Output is correct
13 Correct 4 ms 256 KB Output is correct
14 Correct 3 ms 384 KB Output is correct
15 Correct 4 ms 384 KB Output is correct
16 Correct 6 ms 256 KB Output is correct
17 Correct 11 ms 384 KB Output is correct
18 Correct 17 ms 256 KB Output is correct
19 Correct 8 ms 404 KB Output is correct
20 Correct 22 ms 384 KB Output is correct
21 Correct 15 ms 256 KB Output is correct
22 Correct 13 ms 256 KB Output is correct
23 Correct 17 ms 384 KB Output is correct
24 Correct 9 ms 408 KB Output is correct
25 Correct 19 ms 256 KB Output is correct
26 Correct 20 ms 256 KB Output is correct
27 Correct 13 ms 256 KB Output is correct
28 Correct 21 ms 384 KB Output is correct
29 Correct 20 ms 384 KB Output is correct
30 Correct 19 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 3 ms 384 KB Output is correct
3 Correct 2 ms 256 KB Output is correct
4 Correct 3 ms 384 KB Output is correct
5 Correct 4 ms 384 KB Output is correct
6 Correct 4 ms 384 KB Output is correct
7 Correct 4 ms 256 KB Output is correct
8 Correct 2 ms 384 KB Output is correct
9 Correct 4 ms 380 KB Output is correct
10 Correct 3 ms 256 KB Output is correct
11 Correct 3 ms 256 KB Output is correct
12 Correct 3 ms 256 KB Output is correct
13 Correct 4 ms 256 KB Output is correct
14 Correct 3 ms 384 KB Output is correct
15 Correct 4 ms 384 KB Output is correct
16 Correct 6 ms 256 KB Output is correct
17 Correct 11 ms 384 KB Output is correct
18 Correct 17 ms 256 KB Output is correct
19 Correct 8 ms 404 KB Output is correct
20 Correct 22 ms 384 KB Output is correct
21 Correct 15 ms 256 KB Output is correct
22 Correct 13 ms 256 KB Output is correct
23 Correct 17 ms 384 KB Output is correct
24 Correct 9 ms 408 KB Output is correct
25 Correct 19 ms 256 KB Output is correct
26 Correct 20 ms 256 KB Output is correct
27 Correct 13 ms 256 KB Output is correct
28 Correct 21 ms 384 KB Output is correct
29 Correct 20 ms 384 KB Output is correct
30 Correct 19 ms 384 KB Output is correct
31 Correct 52 ms 256 KB Output is correct
32 Correct 71 ms 384 KB Output is correct
33 Correct 95 ms 376 KB Output is correct
34 Incorrect 78 ms 256 KB Wrong Answer [2]
35 Halted 0 ms 0 KB -