Submission #590480

#TimeUsernameProblemLanguageResultExecution timeMemory
590480HuyXylophone (JOI18_xylophone)C++17
0 / 100
1 ms304 KiB
#include<bits/stdc++.h> #include "xylophone.h" //#define int long long //#define pii pair<int,ll> //#define fi first //#define se second /*#pragma GCC target ("avx2") #pragma GCC optimization ("O3") #pragma GCC optimization ("unroll-loops") #pragma GCC optimize("Ofast") #pragma GCC target("avx,avx2,fma")*/ using namespace std; using ll = long long; using ull = unsigned long long; using ldb = long double; const ll N = (int)1e9 + 1; const int maxN = (int)3e5 + 1; const int mod = 1e9 + 7; //const int mod = 998244353; const ll infty = 1e18 + 7; const int base = (int)4e5; void InputFile() { //freopen("scrivener.inp","r",stdin); //freopen("scrivener.out","w",stdout); //freopen("test.out","r",stdin); } void FastInput() { ios_base::sync_with_stdio(false); cin.tie(nullptr); } int a[5005]; int apr[5005]; void solve(int n) { int low = 1; int high = n; while(low <= high) { int mid = (low + high) / 2; int x = query(mid,n); if(x == n - 1) low = low = mid + 1; else high = mid - 1; } answer(high,1); int pt = high; a[high] = 1; apr[1]++; for(int i = pt - 1; i >= 1; i--) { int diff = query(i,i+1); if(a[i+1] - diff < 1) { a[i] = a[i+1] + diff; answer(i,a[i]); } else if(a[i+1] + diff > n) { a[i] = a[i+1] - diff; answer(i,a[i]); } else { if(apr[a[i+1]-diff]) { a[i] = a[i+1]+diff; answer(i,a[i]); } else if(apr[a[i+1]+diff]) { a[i] = a[i+1] - diff; answer(i,a[i]); } else { int c = a[i+1] - diff; int maxi,mini; maxi = max(max(c,a[i+1]),a[i+2]); mini = min(min(c,a[i+1]),a[i+2]); if(query(i,i+2) == maxi - mini) { a[i] = c; answer(i,c); } else answer(i,a[i+1] + diff); } } apr[a[i]]++; } for(int i = pt + 1; i <= n; i++) { int diff = query(i-1,i); if(a[i-1] - diff < 1) { a[i] = a[i-1] + diff; answer(i,a[i]); } else if(a[i-1] + diff > n) { a[i] = a[i-1] - diff; answer(i,a[i]); } else { if(apr[a[i-1]-diff]) { a[i] = a[i-1] + diff; answer(i,a[i]); } else if(apr[a[i-1]+diff]) { a[i] = a[i-1] - diff; answer(i,a[i]); } else { int c = a[i-1] - diff; int maxi,mini; maxi = max(max(c,a[i-1]),a[i-2]); mini = min(min(c,a[i-1]),a[i-2]); if(query(i-2,i) == maxi - mini) { a[i] = c; answer(i,c); } else answer(i,a[i-1] + diff); } } apr[a[i]]++; } } void Debug() { } /*int32_t main() { FastInput(); //InputFile(); //int sub_type; //cin >> sub_type; //Sieve(); //Prepare(); int test; cin >> test; //test = 1; while(test--) //for(int prc = 1; prc <= test; prc++) { Read(); Solve(); //Debug(); } }*/ /* 2 5 B 0 A 4 B 1 B 3 A 5 B 7 B 2 A 6 B 1 A 7 */

Compilation message (stderr)

xylophone.cpp: In function 'void solve(int)':
xylophone.cpp:48:17: warning: operation on 'low' may be undefined [-Wsequence-point]
   48 |             low = low = mid + 1;
      |             ~~~~^~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...