답안 #763158

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
763158 2023-06-22T05:11:06 Z ind1v Xylophone (JOI18_xylophone) C++11
100 / 100
58 ms 440 KB
#include "xylophone.h"

const int N = 5005;

int a[N];
bool used[N];

bool in(int x, int n) {
  return 1 <= x && x <= n;
}

void solve(int n) {
  int l = 1, r = n, idx = -1;
  while (l <= r) {
    int m = l + r >> 1;
    if (query(1, m) == n - 1) {
      idx = m;
      r = m - 1;
    } else {
      l = m + 1;
    }
  }
  a[idx] = n;
  used[n] = true;
  bool inc = true;
  for (int i = idx + 1; i <= n; i++) {
    if (i == idx + 1) {
      a[i] = n - query(idx, idx + 1);
      used[a[i]] = true;
      inc = false;
    } else {
      int d = query(i - 1, i);
      if (!in(a[i - 1] - d, n)) {
        a[i] = a[i - 1] + d;
      } else if (!in(a[i - 1] + d, n)) {
        a[i] = a[i - 1] - d;
      } else {
        if (used[a[i - 1] - d]) {
          a[i] = a[i - 1] + d;
        } else if (used[a[i - 1] + d]) {
          a[i] = a[i - 1] - d;
        } else {
          if (inc) {
            int dd = query(i - 2, i);
            if (a[i - 1] + d == a[i - 2] + dd) {
              a[i] = a[i - 1] + d;
            } else {
              a[i] = a[i - 1] - d;
            }
          } else {
            int dd = query(i - 2, i);
            if (a[i - 1] - d == a[i - 2] - dd) {
              a[i] = a[i - 1] - d;
            } else {
              a[i] = a[i - 1] + d;
            }
          }
        }
      }
      used[a[i]] = true;
      inc = a[i - 1] < a[i];
    }
  }
  for (int i = idx - 1; i >= 1; i--) {
    if (i == idx - 1) {
      a[i] = n - query(i, i + 1);
      used[a[i]] = true;
      inc = false;
    } else {
      int d = query(i, i + 1);
      if (!in(a[i + 1] - d, n)) {
        a[i] = a[i + 1] + d;
      } else if (!in(a[i + 1] + d, n)) {
        a[i] = a[i + 1] - d;
      } else {
        if (used[a[i + 1] - d]) {
          a[i] = a[i + 1] + d;
        } else if (used[a[i + 1] + d]) {
          a[i] = a[i + 1] - d;
        } else {
          if (inc) {
            int dd = query(i, i + 2);
            if (a[i + 1] + d == a[i + 2] + dd) {
              a[i] = a[i + 1] + d;
            } else {
              a[i] = a[i + 1] - d;
            }
          } else {
            int dd = query(i, i + 2);
            if (a[i + 1] - d == a[i + 2] - dd) {
              a[i] = a[i + 1] - d;
            } else {
              a[i] = a[i + 1] + d;
            }
          }
        }
      }
      used[a[i]] = true;
      inc = a[i] > a[i + 1];
    }
  }
  for(int i = 1; i <= n; i++) {
    answer(i, a[i]);
  }
}

Compilation message

xylophone.cpp: In function 'void solve(int)':
xylophone.cpp:15:15: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   15 |     int m = l + r >> 1;
      |             ~~^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 208 KB Output is correct
2 Correct 0 ms 208 KB Output is correct
3 Correct 1 ms 208 KB Output is correct
4 Correct 2 ms 208 KB Output is correct
5 Correct 1 ms 208 KB Output is correct
6 Correct 1 ms 208 KB Output is correct
7 Correct 1 ms 208 KB Output is correct
8 Correct 1 ms 208 KB Output is correct
9 Correct 1 ms 208 KB Output is correct
10 Correct 1 ms 208 KB Output is correct
11 Correct 1 ms 208 KB Output is correct
12 Correct 1 ms 208 KB Output is correct
13 Correct 1 ms 208 KB Output is correct
14 Correct 1 ms 208 KB Output is correct
15 Correct 2 ms 208 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 208 KB Output is correct
2 Correct 0 ms 208 KB Output is correct
3 Correct 1 ms 208 KB Output is correct
4 Correct 2 ms 208 KB Output is correct
5 Correct 1 ms 208 KB Output is correct
6 Correct 1 ms 208 KB Output is correct
7 Correct 1 ms 208 KB Output is correct
8 Correct 1 ms 208 KB Output is correct
9 Correct 1 ms 208 KB Output is correct
10 Correct 1 ms 208 KB Output is correct
11 Correct 1 ms 208 KB Output is correct
12 Correct 1 ms 208 KB Output is correct
13 Correct 1 ms 208 KB Output is correct
14 Correct 1 ms 208 KB Output is correct
15 Correct 2 ms 208 KB Output is correct
16 Correct 3 ms 208 KB Output is correct
17 Correct 6 ms 208 KB Output is correct
18 Correct 4 ms 208 KB Output is correct
19 Correct 11 ms 292 KB Output is correct
20 Correct 10 ms 296 KB Output is correct
21 Correct 10 ms 292 KB Output is correct
22 Correct 9 ms 292 KB Output is correct
23 Correct 9 ms 292 KB Output is correct
24 Correct 9 ms 296 KB Output is correct
25 Correct 4 ms 292 KB Output is correct
26 Correct 14 ms 208 KB Output is correct
27 Correct 9 ms 288 KB Output is correct
28 Correct 11 ms 292 KB Output is correct
29 Correct 9 ms 208 KB Output is correct
30 Correct 9 ms 292 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 208 KB Output is correct
2 Correct 0 ms 208 KB Output is correct
3 Correct 1 ms 208 KB Output is correct
4 Correct 2 ms 208 KB Output is correct
5 Correct 1 ms 208 KB Output is correct
6 Correct 1 ms 208 KB Output is correct
7 Correct 1 ms 208 KB Output is correct
8 Correct 1 ms 208 KB Output is correct
9 Correct 1 ms 208 KB Output is correct
10 Correct 1 ms 208 KB Output is correct
11 Correct 1 ms 208 KB Output is correct
12 Correct 1 ms 208 KB Output is correct
13 Correct 1 ms 208 KB Output is correct
14 Correct 1 ms 208 KB Output is correct
15 Correct 2 ms 208 KB Output is correct
16 Correct 3 ms 208 KB Output is correct
17 Correct 6 ms 208 KB Output is correct
18 Correct 4 ms 208 KB Output is correct
19 Correct 11 ms 292 KB Output is correct
20 Correct 10 ms 296 KB Output is correct
21 Correct 10 ms 292 KB Output is correct
22 Correct 9 ms 292 KB Output is correct
23 Correct 9 ms 292 KB Output is correct
24 Correct 9 ms 296 KB Output is correct
25 Correct 4 ms 292 KB Output is correct
26 Correct 14 ms 208 KB Output is correct
27 Correct 9 ms 288 KB Output is correct
28 Correct 11 ms 292 KB Output is correct
29 Correct 9 ms 208 KB Output is correct
30 Correct 9 ms 292 KB Output is correct
31 Correct 19 ms 284 KB Output is correct
32 Correct 33 ms 280 KB Output is correct
33 Correct 41 ms 412 KB Output is correct
34 Correct 39 ms 296 KB Output is correct
35 Correct 39 ms 280 KB Output is correct
36 Correct 33 ms 288 KB Output is correct
37 Correct 33 ms 300 KB Output is correct
38 Correct 43 ms 288 KB Output is correct
39 Correct 22 ms 296 KB Output is correct
40 Correct 53 ms 288 KB Output is correct
41 Correct 21 ms 288 KB Output is correct
42 Correct 37 ms 280 KB Output is correct
43 Correct 44 ms 288 KB Output is correct
44 Correct 36 ms 440 KB Output is correct
45 Correct 35 ms 292 KB Output is correct
46 Correct 58 ms 284 KB Output is correct
47 Correct 51 ms 208 KB Output is correct
48 Correct 57 ms 292 KB Output is correct
49 Correct 46 ms 292 KB Output is correct
50 Correct 43 ms 296 KB Output is correct
51 Correct 42 ms 292 KB Output is correct
52 Correct 41 ms 288 KB Output is correct
53 Correct 54 ms 284 KB Output is correct
54 Correct 47 ms 328 KB Output is correct
55 Correct 55 ms 300 KB Output is correct
56 Correct 21 ms 296 KB Output is correct
57 Correct 41 ms 292 KB Output is correct
58 Correct 41 ms 300 KB Output is correct
59 Correct 40 ms 292 KB Output is correct
60 Correct 34 ms 288 KB Output is correct