Submission #255415

# Submission time Handle Problem Language Result Execution time Memory
255415 2020-07-31T21:54:54 Z ChrisT Xylophone (JOI18_xylophone) C++17
100 / 100
146 ms 528 KB
#include<bits/stdc++.h>
#include "xylophone.h"
using namespace std;
bool same[5005]; int diff[5005];
void solve (int n) {
  for (int i = 1; i < n; i++) diff[i] = query(i,i+1);
  for (int i = 1; i + 1 < n; i++) same[i+1] = query(i,i+2) == diff[i] + diff[i+1];
  for (int ree = 0; ree <= 1; ree++) {
    int lt = ree; vector<int> perm(n+1);
    for (int st = 1; st <= n; st++) {
      lt = ree; perm[1] = st;
      for (int j = 2; j <= n; j++) {
        if (lt) perm[j] = perm[j-1] - diff[j-1];
        else perm[j] = perm[j-1] + diff[j-1];
        if (perm[j] < 1 || perm[j] > n) goto fail;
        lt ^= same[j] ^ 1;
      }
      for (int i = 1; i <= n; i++) {
        if (perm[i] == 1) break;
        if (perm[i] == n) goto fail;
      }
      for (int i = 1; i <= n; i++) answer(i,perm[i]);
      return;
      fail:;
    }
  }
  assert(0);
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 256 KB Output is correct
2 Correct 1 ms 256 KB Output is correct
3 Correct 2 ms 256 KB Output is correct
4 Correct 3 ms 256 KB Output is correct
5 Correct 3 ms 256 KB Output is correct
6 Correct 3 ms 256 KB Output is correct
7 Correct 3 ms 256 KB Output is correct
8 Correct 2 ms 256 KB Output is correct
9 Correct 1 ms 380 KB Output is correct
10 Correct 2 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 3 ms 384 KB Output is correct
14 Correct 3 ms 384 KB Output is correct
15 Correct 2 ms 256 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 256 KB Output is correct
2 Correct 1 ms 256 KB Output is correct
3 Correct 2 ms 256 KB Output is correct
4 Correct 3 ms 256 KB Output is correct
5 Correct 3 ms 256 KB Output is correct
6 Correct 3 ms 256 KB Output is correct
7 Correct 3 ms 256 KB Output is correct
8 Correct 2 ms 256 KB Output is correct
9 Correct 1 ms 380 KB Output is correct
10 Correct 2 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 3 ms 384 KB Output is correct
14 Correct 3 ms 384 KB Output is correct
15 Correct 2 ms 256 KB Output is correct
16 Correct 6 ms 384 KB Output is correct
17 Correct 13 ms 256 KB Output is correct
18 Correct 22 ms 384 KB Output is correct
19 Correct 25 ms 376 KB Output is correct
20 Correct 28 ms 376 KB Output is correct
21 Correct 25 ms 376 KB Output is correct
22 Correct 27 ms 384 KB Output is correct
23 Correct 26 ms 384 KB Output is correct
24 Correct 27 ms 384 KB Output is correct
25 Correct 25 ms 376 KB Output is correct
26 Correct 27 ms 376 KB Output is correct
27 Correct 27 ms 384 KB Output is correct
28 Correct 26 ms 384 KB Output is correct
29 Correct 18 ms 372 KB Output is correct
30 Correct 19 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 256 KB Output is correct
2 Correct 1 ms 256 KB Output is correct
3 Correct 2 ms 256 KB Output is correct
4 Correct 3 ms 256 KB Output is correct
5 Correct 3 ms 256 KB Output is correct
6 Correct 3 ms 256 KB Output is correct
7 Correct 3 ms 256 KB Output is correct
8 Correct 2 ms 256 KB Output is correct
9 Correct 1 ms 380 KB Output is correct
10 Correct 2 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 3 ms 384 KB Output is correct
14 Correct 3 ms 384 KB Output is correct
15 Correct 2 ms 256 KB Output is correct
16 Correct 6 ms 384 KB Output is correct
17 Correct 13 ms 256 KB Output is correct
18 Correct 22 ms 384 KB Output is correct
19 Correct 25 ms 376 KB Output is correct
20 Correct 28 ms 376 KB Output is correct
21 Correct 25 ms 376 KB Output is correct
22 Correct 27 ms 384 KB Output is correct
23 Correct 26 ms 384 KB Output is correct
24 Correct 27 ms 384 KB Output is correct
25 Correct 25 ms 376 KB Output is correct
26 Correct 27 ms 376 KB Output is correct
27 Correct 27 ms 384 KB Output is correct
28 Correct 26 ms 384 KB Output is correct
29 Correct 18 ms 372 KB Output is correct
30 Correct 19 ms 376 KB Output is correct
31 Correct 53 ms 376 KB Output is correct
32 Correct 79 ms 376 KB Output is correct
33 Correct 115 ms 376 KB Output is correct
34 Correct 127 ms 392 KB Output is correct
35 Correct 103 ms 376 KB Output is correct
36 Correct 134 ms 376 KB Output is correct
37 Correct 146 ms 528 KB Output is correct
38 Correct 136 ms 504 KB Output is correct
39 Correct 133 ms 376 KB Output is correct
40 Correct 106 ms 376 KB Output is correct
41 Correct 122 ms 376 KB Output is correct
42 Correct 88 ms 376 KB Output is correct
43 Correct 137 ms 376 KB Output is correct
44 Correct 125 ms 376 KB Output is correct
45 Correct 88 ms 376 KB Output is correct
46 Correct 125 ms 504 KB Output is correct
47 Correct 92 ms 516 KB Output is correct
48 Correct 133 ms 376 KB Output is correct
49 Correct 136 ms 376 KB Output is correct
50 Correct 107 ms 376 KB Output is correct
51 Correct 88 ms 376 KB Output is correct
52 Correct 135 ms 396 KB Output is correct
53 Correct 83 ms 376 KB Output is correct
54 Correct 94 ms 384 KB Output is correct
55 Correct 79 ms 376 KB Output is correct
56 Correct 84 ms 384 KB Output is correct
57 Correct 88 ms 512 KB Output is correct
58 Correct 74 ms 376 KB Output is correct
59 Correct 121 ms 376 KB Output is correct
60 Correct 97 ms 504 KB Output is correct