답안 #915129

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
915129 2024-01-23T11:31:26 Z OAleksa Xylophone (JOI18_xylophone) C++14
100 / 100
36 ms 1204 KB
#include "xylophone.h"
#include<bits/stdc++.h>
using namespace std;
const int MAXN = 5069;
int ans[MAXN], vis[MAXN];
void solve(int N) {
  int n = N;
	int l = 2, r = n, mx = 2;
	while (l <= r) {
    int mid = (l + r) / 2;
    if (query(1, mid) == n - 1) {
      mx = mid;
      r = mid - 1;
    }
    else
      l = mid + 1;
	}
	ans[mx] = n;
	vis[n] = 1;
	if (mx < n) {
    int x = query(mx, mx + 1);
    ans[mx + 1] = n - x;
    vis[n - x] = 1;
	}
  int x = query(mx - 1, mx);
  ans[mx - 1] = n - x;
  vis[n - x] = 1;
  for (int i = mx - 2;i >= 1;i--) {
    int x = query(i, i + 1);
    int v1 = ans[i + 1] - x;
    int v2 = ans[i + 1] + x;
    if (v1 < 1 || v1 > n || vis[v1])
      ans[i] = v2;
    else if (v2 > n || v2 < 1 || vis[v2])
      ans[i] = v1;
    else {
      int y = query(i, i + 2);
      if (y == abs(ans[i + 2] - ans[i + 1]) || y == x) {
        if (ans[i + 2] > ans[i + 1])
          ans[i] = v2;
        else
          ans[i] = v1;
      }
      else {
         if (ans[i + 2] > ans[i + 1])
          ans[i] = v1;
        else
          ans[i] = v2;
      }
    }
    vis[ans[i]] = 1;
  }
  for (int i = mx + 2;i < n;i++) {
    int x = query(i - 1, i);
    int v1 = ans[i - 1] - x;
    int v2 = ans[i - 1] + x;
    if (v1 < 1 || v1 > n || vis[v1])
      ans[i] = v2;
    else if (v2 > n || v2 > n || vis[v2])
      ans[i] = v1;
    else {
      int y = query(i - 2, i);
      if (y == abs(ans[i - 2] - ans[i - 1]) || y == x) {
        if (ans[i - 2] > ans[i - 1])
          ans[i] = v2;
        else
          ans[i] = v1;
      }
      else {
        if (ans[i - 2] > ans[i - 1])
          ans[i] = v1;
        else
          ans[i] = v2;
      }
    }
    vis[ans[i]] = 1;
  }
  for (int i = 1;i <= n;i++) {
    if (!vis[i])
      ans[n] = i;
  }
	for(int i = 1; i <= n; i++) {
		answer(i, ans[i]);
	}
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 444 KB Output is correct
2 Correct 1 ms 440 KB Output is correct
3 Correct 1 ms 436 KB Output is correct
4 Correct 1 ms 440 KB Output is correct
5 Correct 1 ms 444 KB Output is correct
6 Correct 1 ms 440 KB Output is correct
7 Correct 1 ms 436 KB Output is correct
8 Correct 1 ms 436 KB Output is correct
9 Correct 1 ms 444 KB Output is correct
10 Correct 1 ms 440 KB Output is correct
11 Correct 1 ms 440 KB Output is correct
12 Correct 1 ms 440 KB Output is correct
13 Correct 1 ms 444 KB Output is correct
14 Correct 1 ms 436 KB Output is correct
15 Correct 1 ms 436 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 444 KB Output is correct
2 Correct 1 ms 440 KB Output is correct
3 Correct 1 ms 436 KB Output is correct
4 Correct 1 ms 440 KB Output is correct
5 Correct 1 ms 444 KB Output is correct
6 Correct 1 ms 440 KB Output is correct
7 Correct 1 ms 436 KB Output is correct
8 Correct 1 ms 436 KB Output is correct
9 Correct 1 ms 444 KB Output is correct
10 Correct 1 ms 440 KB Output is correct
11 Correct 1 ms 440 KB Output is correct
12 Correct 1 ms 440 KB Output is correct
13 Correct 1 ms 444 KB Output is correct
14 Correct 1 ms 436 KB Output is correct
15 Correct 1 ms 436 KB Output is correct
16 Correct 2 ms 596 KB Output is correct
17 Correct 3 ms 696 KB Output is correct
18 Correct 6 ms 692 KB Output is correct
19 Correct 6 ms 448 KB Output is correct
20 Correct 5 ms 440 KB Output is correct
21 Correct 5 ms 696 KB Output is correct
22 Correct 5 ms 692 KB Output is correct
23 Correct 5 ms 448 KB Output is correct
24 Correct 5 ms 448 KB Output is correct
25 Correct 5 ms 700 KB Output is correct
26 Correct 7 ms 704 KB Output is correct
27 Correct 7 ms 704 KB Output is correct
28 Correct 6 ms 692 KB Output is correct
29 Correct 5 ms 452 KB Output is correct
30 Correct 6 ms 444 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 444 KB Output is correct
2 Correct 1 ms 440 KB Output is correct
3 Correct 1 ms 436 KB Output is correct
4 Correct 1 ms 440 KB Output is correct
5 Correct 1 ms 444 KB Output is correct
6 Correct 1 ms 440 KB Output is correct
7 Correct 1 ms 436 KB Output is correct
8 Correct 1 ms 436 KB Output is correct
9 Correct 1 ms 444 KB Output is correct
10 Correct 1 ms 440 KB Output is correct
11 Correct 1 ms 440 KB Output is correct
12 Correct 1 ms 440 KB Output is correct
13 Correct 1 ms 444 KB Output is correct
14 Correct 1 ms 436 KB Output is correct
15 Correct 1 ms 436 KB Output is correct
16 Correct 2 ms 596 KB Output is correct
17 Correct 3 ms 696 KB Output is correct
18 Correct 6 ms 692 KB Output is correct
19 Correct 6 ms 448 KB Output is correct
20 Correct 5 ms 440 KB Output is correct
21 Correct 5 ms 696 KB Output is correct
22 Correct 5 ms 692 KB Output is correct
23 Correct 5 ms 448 KB Output is correct
24 Correct 5 ms 448 KB Output is correct
25 Correct 5 ms 700 KB Output is correct
26 Correct 7 ms 704 KB Output is correct
27 Correct 7 ms 704 KB Output is correct
28 Correct 6 ms 692 KB Output is correct
29 Correct 5 ms 452 KB Output is correct
30 Correct 6 ms 444 KB Output is correct
31 Correct 11 ms 952 KB Output is correct
32 Correct 19 ms 948 KB Output is correct
33 Correct 25 ms 708 KB Output is correct
34 Correct 29 ms 696 KB Output is correct
35 Correct 28 ms 952 KB Output is correct
36 Correct 20 ms 1200 KB Output is correct
37 Correct 23 ms 1204 KB Output is correct
38 Correct 24 ms 948 KB Output is correct
39 Correct 31 ms 688 KB Output is correct
40 Correct 30 ms 704 KB Output is correct
41 Correct 28 ms 468 KB Output is correct
42 Correct 21 ms 704 KB Output is correct
43 Correct 23 ms 948 KB Output is correct
44 Correct 23 ms 960 KB Output is correct
45 Correct 30 ms 956 KB Output is correct
46 Correct 29 ms 952 KB Output is correct
47 Correct 32 ms 700 KB Output is correct
48 Correct 32 ms 700 KB Output is correct
49 Correct 30 ms 704 KB Output is correct
50 Correct 36 ms 696 KB Output is correct
51 Correct 30 ms 952 KB Output is correct
52 Correct 30 ms 704 KB Output is correct
53 Correct 27 ms 964 KB Output is correct
54 Correct 29 ms 736 KB Output is correct
55 Correct 28 ms 944 KB Output is correct
56 Correct 29 ms 948 KB Output is correct
57 Correct 26 ms 704 KB Output is correct
58 Correct 29 ms 720 KB Output is correct
59 Correct 29 ms 712 KB Output is correct
60 Correct 30 ms 692 KB Output is correct