Submission #996086

# Submission time Handle Problem Language Result Execution time Memory
996086 2024-06-10T07:48:38 Z fimh Xylophone (JOI18_xylophone) C++14
0 / 100
0 ms 344 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, n;
ll a[N], qr[N][2];
bool f[N];

bool check(){
     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 i = 1; i < n; ++i){
          a[1] = i;
          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 (t2 < t1) a[i] = a[i - 1] + t1;
                         else a[i] = a[i - 1] - t1;
                    }else{
                         if (t2 > t1) a[i] = a[i - 1] + t1;
                         else a[i] = a[i - 1] - t1; 
                    }
               }
               if (check()) 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 (t2 < t1) a[i] = a[i - 1] + t1;
                         else a[i] = a[i - 1] - t1;
                    }else{
                         if (t2 > t1) a[i] = a[i - 1] + t1;
                         else a[i] = a[i - 1] - t1; 
                    }
               }
               if (check()) 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 Incorrect 0 ms 344 KB Wrong Answer [7]
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Incorrect 0 ms 344 KB Wrong Answer [7]
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Incorrect 0 ms 344 KB Wrong Answer [7]
3 Halted 0 ms 0 KB -