Submission #996088

#TimeUsernameProblemLanguageResultExecution timeMemory
996088BuzzyBeezXylophone (JOI18_xylophone)C++17
100 / 100
135 ms1104 KiB
#include<bits/stdc++.h> #include "xylophone.h" #define ll long long #define ull unsigned long long #define ld long double #define pb push_back #define pf push_front #define vi vector<int> #define vii vector<vi> #define pint pair<int,int> #define vpint vector<pint> #define aint(a) a.begin(), a.end() #define fi first #define se second using namespace std; const ll mod = 1e9+7; const ll inf = 1e18; const ll base = 31; const ll blocksz = 320; const ll N = 1e4+8; const ll buff = 1e5+1; int a[N],dist[N][2]; int pos[5008]; bool check(int n) { fill(pos + 1, pos + n + 1, 0); for (int i = 1; i <= n; ++i) if (a[i] <= 0 || a[i] > n) return 0; else pos[a[i]] = i; for (int i = 1; i <= n; ++i) if (!pos[i]) return 0; return pos[1] < pos[n]; } void solve(int n){ for(int i = 2; i <= n; i++){ if(i > 1) dist[i][0] = query(i-1,i); if(i > 2) dist[i][1] = query(i-2,i); } for(int x = 1; x <= n; x++){ a[1] = x; a[2] = x+dist[2][0]; for(int i = 3; i <= n; i++){ if(a[i-2] > a[i-1]){ if (a[i-2]-a[i-1]+dist[i][0] == dist[i][1]) a[i] = a[i-1]-dist[i][0]; else a[i] = a[i-1]+dist[i][0]; } else{ if (a[i-1]-a[i-2]+dist[i][0] == dist[i][1]) a[i] = a[i-1]+dist[i][0]; else a[i] = a[i-1]-dist[i][0]; } } if(check(n)) break; a[1] = x; a[2] = x-dist[2][0]; for(int i = 3; i <= n; i++){ if(a[i-2] > a[i-1]){ if (a[i-2]-a[i-1]+dist[i][0] == dist[i][1]) a[i] = a[i-1]-dist[i][0]; else a[i] = a[i-1]+dist[i][0]; } else{ if (a[i-1]-a[i-2]+dist[i][0] == dist[i][1]) a[i] = a[i-1]+dist[i][0]; else a[i] = a[i-1]-dist[i][0]; } } if(check(n)) break; } for(int i = 1; i <= n; i++) answer(i,a[i]); }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...