제출 #433882

#제출 시각아이디문제언어결과실행 시간메모리
433882LouayFarahXylophone (JOI18_xylophone)C++14
0 / 100
2 ms200 KiB
#include "bits/stdc++.h" #include "xylophone.h" using namespace std; #define pb push_back void solve(int n) { vector<int> arr(n+1); /*for(auto elt: arr) cout << elt << ' '; cout << endl;*/ /*orig.resize(n+1); for(int i = 1; i<=n; i++) cin >> orig[i];*/ int l = 1, r = n-1; int maxdif = n-1; while(maxdif==n-1) { maxdif = query(l, r); r--; } r+=2, l++; maxdif = n-1; while(maxdif==n-1) { maxdif = query(l, r); l++; } l-=2; arr[l] = 1; arr[r] = n; //cout << l << ' ' << r << endl; if(r-l>1) { maxdif = query(l, l+1); arr[l+1] = maxdif+1; } for(int i = l+2; i<r; i++) { int dif = query(l, i); if(dif==maxdif) { int dif2 = query(l+1, i); arr[i] = arr[l+1]-dif2; } else { arr[i] = dif + 1; } } if(l>1) { maxdif = query(l-1, l); arr[l-1] = maxdif+1; } for(int i = l-2; i>=1; i--) { int dif = query(i, l); if(dif==maxdif) { int dif2 = query(l-1, i); arr[i] = arr[l-1]-dif2; } else { arr[i] = dif+1; } } if(r<n) { maxdif = query(r, r+1); arr[r+1] = n-maxdif; } for(int i = r+2; i<=n; i++) { int dif = query(r, i); if(dif==maxdif) { int dif2 = query(r+1, i); arr[i] = arr[r+1] + dif2; } else { arr[i] = n-dif; } } for(int i = 1; i<=n; i++) { answer(i, arr[i]); } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...