Submission #996086

#TimeUsernameProblemLanguageResultExecution timeMemory
996086fimhXylophone (JOI18_xylophone)C++14
0 / 100
0 ms344 KiB
#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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...