Submission #363242

# Submission time Handle Problem Language Result Execution time Memory
363242 2021-02-05T11:11:06 Z buyolitsez Xylophone (JOI18_xylophone) C++17
47 / 100
102 ms 748 KB
#include "xylophone.h"
#include <bits/stdc++.h>

using namespace std;

bool Check(int a, int b, int c, int i) {
    if (a == b || b == c || a == c) {return false;}
    if (a > b && b > c) {
        return query(i + 1, i + 3) == a - c;
    }
    if (a > c && c > b) {
        return query(i + 1, i + 3) == a - b;
    }
    if (c > a && a > b) {
        return query(i + 1, i + 3) == c - b;
    }
    if (c > b && b > a) {
        return query(i + 1, i + 3) == c - a;
    }
    if (b > a && a > c) {
        return query(i + 1, i + 3) == b - c;
    }
    if (b > c && c > a) {
        return query(i + 1, i + 3) == b - a;
    }
}

int GetRight(int n, int a, int b, int x, int i) {
    int c1 = b + x, c2 = b - x;
    if (c1 > n) {return c2;}
    if (c2 < 1) {return c1;}
    if (Check(a, b, c1, i)) {
        return c1;
    }
    return c2;
}

int GetLeft(int n, int a, int b, int x, int i) {
    int c1 = a + x, c2 = a - x;
    if (c1 > n) {return c2;}
    if (c2 < 1) {return c1;}
    if (Check(c1, a, b, i)) {
        return c1;
    }
    return c2;
}


void solve(int n) {
    int pos = n - 1;
    while (query(1, pos) == n - 1) {
        --pos;
    }
    vector <int> num(n);
    num[pos] = n;
    if (pos + 1 < n) {
        int x = query(pos + 1, pos + 2);
        num[pos + 1] = n - x;
    }
    vector <vector<int>> cand1(n), cand2(n);
    for (int i = pos + 2; i < n; ++i) {
        int x = query(i, i + 1);
        num[i] = GetRight(n, num[i - 2], num[i - 1], x, i - 2);
    }
    if (pos != 0) {
        int x = query(pos, pos + 1);
        num[pos - 1] = n - x;
    }
    for (int i = pos - 2; i >= 0; --i) {
        int x = query(i + 1, i + 2);
        num[i] = GetLeft(n, num[i + 1], num[i + 2], x, i);
    }
    for(int i = 0; i < n; ++i) {
        answer(i + 1, num[i]);
    }
}

Compilation message

xylophone.cpp: In function 'bool Check(int, int, int, int)':
xylophone.cpp:26:1: warning: control reaches end of non-void function [-Wreturn-type]
   26 | }
      | ^
# Verdict Execution time Memory Grader output
1 Correct 0 ms 364 KB Output is correct
2 Correct 0 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 2 ms 384 KB Output is correct
5 Correct 2 ms 364 KB Output is correct
6 Correct 3 ms 364 KB Output is correct
7 Correct 3 ms 364 KB Output is correct
8 Correct 2 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 4 ms 364 KB Output is correct
11 Correct 2 ms 364 KB Output is correct
12 Correct 2 ms 364 KB Output is correct
13 Correct 2 ms 364 KB Output is correct
14 Correct 1 ms 376 KB Output is correct
15 Correct 2 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 364 KB Output is correct
2 Correct 0 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 2 ms 384 KB Output is correct
5 Correct 2 ms 364 KB Output is correct
6 Correct 3 ms 364 KB Output is correct
7 Correct 3 ms 364 KB Output is correct
8 Correct 2 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 4 ms 364 KB Output is correct
11 Correct 2 ms 364 KB Output is correct
12 Correct 2 ms 364 KB Output is correct
13 Correct 2 ms 364 KB Output is correct
14 Correct 1 ms 376 KB Output is correct
15 Correct 2 ms 364 KB Output is correct
16 Correct 5 ms 368 KB Output is correct
17 Correct 10 ms 364 KB Output is correct
18 Correct 16 ms 364 KB Output is correct
19 Correct 15 ms 364 KB Output is correct
20 Correct 18 ms 364 KB Output is correct
21 Correct 17 ms 492 KB Output is correct
22 Correct 13 ms 364 KB Output is correct
23 Correct 10 ms 492 KB Output is correct
24 Correct 12 ms 492 KB Output is correct
25 Correct 20 ms 364 KB Output is correct
26 Correct 16 ms 492 KB Output is correct
27 Correct 21 ms 364 KB Output is correct
28 Correct 21 ms 512 KB Output is correct
29 Correct 17 ms 364 KB Output is correct
30 Correct 16 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 364 KB Output is correct
2 Correct 0 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 2 ms 384 KB Output is correct
5 Correct 2 ms 364 KB Output is correct
6 Correct 3 ms 364 KB Output is correct
7 Correct 3 ms 364 KB Output is correct
8 Correct 2 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 4 ms 364 KB Output is correct
11 Correct 2 ms 364 KB Output is correct
12 Correct 2 ms 364 KB Output is correct
13 Correct 2 ms 364 KB Output is correct
14 Correct 1 ms 376 KB Output is correct
15 Correct 2 ms 364 KB Output is correct
16 Correct 5 ms 368 KB Output is correct
17 Correct 10 ms 364 KB Output is correct
18 Correct 16 ms 364 KB Output is correct
19 Correct 15 ms 364 KB Output is correct
20 Correct 18 ms 364 KB Output is correct
21 Correct 17 ms 492 KB Output is correct
22 Correct 13 ms 364 KB Output is correct
23 Correct 10 ms 492 KB Output is correct
24 Correct 12 ms 492 KB Output is correct
25 Correct 20 ms 364 KB Output is correct
26 Correct 16 ms 492 KB Output is correct
27 Correct 21 ms 364 KB Output is correct
28 Correct 21 ms 512 KB Output is correct
29 Correct 17 ms 364 KB Output is correct
30 Correct 16 ms 364 KB Output is correct
31 Correct 25 ms 492 KB Output is correct
32 Correct 49 ms 620 KB Output is correct
33 Correct 81 ms 600 KB Output is correct
34 Correct 88 ms 620 KB Output is correct
35 Correct 70 ms 748 KB Output is correct
36 Correct 47 ms 744 KB Output is correct
37 Correct 72 ms 620 KB Output is correct
38 Incorrect 102 ms 620 KB Wrong Answer [2]
39 Halted 0 ms 0 KB -