Submission #996138

# Submission time Handle Problem Language Result Execution time Memory
996138 2024-06-10T08:13:59 Z fimh Xylophone (JOI18_xylophone) C++14
100 / 100
140 ms 976 KB
#include <bits/stdc++.h>
#include "xylophone.h"
using namespace std; 

using ll = long long;
using pll = pair<ll, ll>;

#define fi first
#define se second

const ll N = 5e3 + 5;
const ll blocksz = 320;
const ll mod = 1e9 + 7;
const ll inf = 1e18;

ll rep;
ll a[N], qr[N][2];
bool f[N];

bool check(int n){
     for (int i = 1; i <= n; ++i){
          if (a[i] == n) return 0;
          if (a[i] == 1) break;
     }
     if (*min_element(a + 1, a + n + 1) != 1) return 0;
     if (*max_element(a + 1, a + n + 1) != n) return 0;
     for (int i = 1; i <= n; ++i) f[i] = 0;
     for (int i = 1; i <= n; ++i) f[a[i]] = 1;
     for (int i = 1; i <= n; ++i) if (!f[i]) return 0;
     return 1;
}

// ll query(ll l, ll r){
//      cout << l << " " << r << endl;
//      cin >> rep;
//      return rep;
// }

// void answer(ll i, ll x){
//      a[i] = x;
// }

void solve(int n){
     // cin >> n;
     ll d = query(1, 2);
     for (int i = 3; i <= n; ++i){
          qr[i][0] = query(i - 1, i);
          qr[i][1] = query(i - 2, i);
     }
     for (int x = 1; x < n; ++x){
          a[1] = x;
          if (a[1] - d >= 1){
               a[2] = a[1] - d;
               for (int i = 3; i <= n; ++i){
                    ll t1 = qr[i][0];
                    ll t2 = qr[i][1];
                    if (a[i - 2] > a[i - 1]){
                         if (t1 - t2 == a[i - 1] - a[i - 2]) a[i] = a[i - 1] - t1;
                         else a[i] = a[i - 1] + t1;
                    }else{ // a[i - 2] < a[i - 1]
                         if (t1 - t2 == a[i - 2] - a[i - 1]) a[i] = a[i - 1] + t1;
                         else a[i] = a[i - 1] - t1;
                    }
               }
               if (check(n)) break;
          }
          if (a[1] + d <= n){
               a[2] = a[1] + d;
               for (int i = 3; i <= n; ++i){
                    ll t1 = qr[i][0];
                    ll t2 = qr[i][1];
                    if (a[i - 2] > a[i - 1]){
                         if (t1 - t2 == a[i - 1] - a[i - 2]) a[i] = a[i - 1] - t1;
                         else a[i] = a[i - 1] + t1;
                    }else{
                         if (t1 - t2 == a[i - 2] - a[i - 1]) a[i] = a[i - 1] + t1;
                         else a[i] = a[i - 1] - t1;
                    }
               }
               if (check(n)) break;
          }
     }
     for (int i = 1; i <= n; ++i) answer(i, a[i]);
}         
     
// signed main(){
//      // ios_base::sync_with_stdio(0); 
//      // cin.tie(0); cout.tie(0);
//      ll TC = 1; // cin >> TC;
//      while (TC--){
//           solve();
//      }
// }
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Correct 1 ms 344 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
6 Correct 1 ms 344 KB Output is correct
7 Correct 1 ms 444 KB Output is correct
8 Correct 1 ms 344 KB Output is correct
9 Correct 2 ms 344 KB Output is correct
10 Correct 1 ms 344 KB Output is correct
11 Correct 1 ms 344 KB Output is correct
12 Correct 1 ms 344 KB Output is correct
13 Correct 1 ms 408 KB Output is correct
14 Correct 1 ms 344 KB Output is correct
15 Correct 1 ms 344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Correct 1 ms 344 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
6 Correct 1 ms 344 KB Output is correct
7 Correct 1 ms 444 KB Output is correct
8 Correct 1 ms 344 KB Output is correct
9 Correct 2 ms 344 KB Output is correct
10 Correct 1 ms 344 KB Output is correct
11 Correct 1 ms 344 KB Output is correct
12 Correct 1 ms 344 KB Output is correct
13 Correct 1 ms 408 KB Output is correct
14 Correct 1 ms 344 KB Output is correct
15 Correct 1 ms 344 KB Output is correct
16 Correct 2 ms 344 KB Output is correct
17 Correct 5 ms 344 KB Output is correct
18 Correct 7 ms 600 KB Output is correct
19 Correct 15 ms 604 KB Output is correct
20 Correct 15 ms 600 KB Output is correct
21 Correct 14 ms 464 KB Output is correct
22 Correct 12 ms 476 KB Output is correct
23 Correct 9 ms 452 KB Output is correct
24 Correct 12 ms 448 KB Output is correct
25 Correct 8 ms 344 KB Output is correct
26 Correct 18 ms 600 KB Output is correct
27 Correct 6 ms 344 KB Output is correct
28 Correct 12 ms 600 KB Output is correct
29 Correct 13 ms 344 KB Output is correct
30 Correct 10 ms 344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Correct 1 ms 344 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
6 Correct 1 ms 344 KB Output is correct
7 Correct 1 ms 444 KB Output is correct
8 Correct 1 ms 344 KB Output is correct
9 Correct 2 ms 344 KB Output is correct
10 Correct 1 ms 344 KB Output is correct
11 Correct 1 ms 344 KB Output is correct
12 Correct 1 ms 344 KB Output is correct
13 Correct 1 ms 408 KB Output is correct
14 Correct 1 ms 344 KB Output is correct
15 Correct 1 ms 344 KB Output is correct
16 Correct 2 ms 344 KB Output is correct
17 Correct 5 ms 344 KB Output is correct
18 Correct 7 ms 600 KB Output is correct
19 Correct 15 ms 604 KB Output is correct
20 Correct 15 ms 600 KB Output is correct
21 Correct 14 ms 464 KB Output is correct
22 Correct 12 ms 476 KB Output is correct
23 Correct 9 ms 452 KB Output is correct
24 Correct 12 ms 448 KB Output is correct
25 Correct 8 ms 344 KB Output is correct
26 Correct 18 ms 600 KB Output is correct
27 Correct 6 ms 344 KB Output is correct
28 Correct 12 ms 600 KB Output is correct
29 Correct 13 ms 344 KB Output is correct
30 Correct 10 ms 344 KB Output is correct
31 Correct 41 ms 456 KB Output is correct
32 Correct 51 ms 704 KB Output is correct
33 Correct 57 ms 344 KB Output is correct
34 Correct 104 ms 700 KB Output is correct
35 Correct 72 ms 592 KB Output is correct
36 Correct 53 ms 484 KB Output is correct
37 Correct 86 ms 692 KB Output is correct
38 Correct 80 ms 344 KB Output is correct
39 Correct 57 ms 972 KB Output is correct
40 Correct 89 ms 600 KB Output is correct
41 Correct 103 ms 948 KB Output is correct
42 Correct 75 ms 448 KB Output is correct
43 Correct 105 ms 692 KB Output is correct
44 Correct 68 ms 940 KB Output is correct
45 Correct 87 ms 692 KB Output is correct
46 Correct 129 ms 344 KB Output is correct
47 Correct 140 ms 856 KB Output is correct
48 Correct 54 ms 708 KB Output is correct
49 Correct 121 ms 456 KB Output is correct
50 Correct 139 ms 600 KB Output is correct
51 Correct 63 ms 344 KB Output is correct
52 Correct 53 ms 344 KB Output is correct
53 Correct 122 ms 976 KB Output is correct
54 Correct 116 ms 460 KB Output is correct
55 Correct 94 ms 592 KB Output is correct
56 Correct 74 ms 344 KB Output is correct
57 Correct 105 ms 592 KB Output is correct
58 Correct 57 ms 600 KB Output is correct
59 Correct 83 ms 344 KB Output is correct
60 Correct 76 ms 452 KB Output is correct