# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
85578 | KCSC | Xylophone (JOI18_xylophone) | C++14 | 0 ms | 0 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
const int DIM = 5005;
int vec[DIM], dif[DIM], sol[DIM], arr[DIM];
/*
int query(int l, int r) {
int mn = 1e9, mx = -1e9;
for (int i = l; i <= r; ++i) {
mn = min(mn, arr[i]); mx = max(mx, arr[i]); }
return mx - mn; }
*/
int _query(int l, int r) {
static map<pair<int, int>, int> mmp;
if (mmp.find(make_pair(l, r)) == mmp.end())
mmp[make_pair(l, r)] = query(l, r);
return mmp[make_pair(l, r)]; }
/*
void answer(int p, int v) {
sol[p] = v; }
*/
void solve(int n) {
vec[2] = query(1, 2);
for (int i = 3, l = 1, s = 1; i <= n; ++i) {
if (_query(l, i) != _query(l, i - 1) + _query(i - 1, i)) {
s *= -1; l = i - 1; }
vec[i] = s * _query(i - 1, i); }
int mn = 0;
for (int i = 2; i <= n; ++i) {
vec[i] += vec[i - 1]; mn = min(mn, vec[i]); }
int p1 = 0, pn = 0;
for (int i = 1; i <= n; ++i) {
vec[i] += 1 - mn;
if (vec[i] == 1) { p1 = i; }
if (vec[i] == n) { pn = i; } }
if (p1 > pn) {
for (int i = 1; i <= n; ++i) {
vec[i] = n + 1 - vec[i]; } }
for (int i = 1; i <= n; ++i) {
answer(i, vec[i]); } }
/*
int main(void) {
#ifdef HOME
freopen("xylophone.in", "r", stdin);
freopen("xylophone.out", "w", stdout);
#endif
int n; cin >> n;
for (int i = 1; i <= n; ++i) {
cin >> arr[i]; cout << arr[i] << " "; }
solve(n); cout << "\n";
for (int i = 1; i <= n; ++i) {
cout << sol[i] << " "; }
return 0; }
*/