# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
470690 | Millad | 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.
// In the name of god
#include "Xylophone.h"
#include <bits/stdc++.h>
#define F first
#define S second
#define pb push_back
#define debug(x) cerr << #x << " : " << x << '\n'
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pll;
const ll maxn = 5e3 + 5;
ll b1[maxn], b2[maxn], d1[maxn], d2[maxn];
bool flag1[maxn], flag2[maxn];
void build_b1(int n){
flag1[1] = 1;
for(ll i = 1; i < n; i ++){
if(flag1[i])b1[i + 1] = b1[i] + d1[i];
else b1[i + 1] = b1[i] - d1[i];
if(i < n - 1){
if(d2[i] == d1[i] + d1[i + 1])flag1[i + 1] = flag1[i];
else flag1[i + 1] = !flag1[i];
}
}
ll mn = -(n * 10);
for(ll i = 1; i <= n; i ++)mn = min(mn, b1[i]);
for(ll i = 1; i <= n; i ++)b1[i] += (1 - mn);
}
void build_b2(int n){
flag2[1] = 1;
for(ll i = 1; i < n; i ++){
if(flag2[i])b2[i + 1] = b2[i] + d1[i];
else b2[i + 1] = b2[i] - d1[i];
if(i < n - 1){
if(d2[i] == d1[i] + d1[i + 1])flag2[i + 1] = flag2[i];
else flag2[i + 1] = !flag2[i];
}
}
ll mn = -(n * 10);
for(ll i = 1; i <= n; i ++)mn = min(mn, b2[i]);
for(ll i = 1; i <= n; i ++)b2[i] += (1 - mn);
}
void solve(int n){
for(ll i = 1; i < n; i ++)d1[i] = query(i, i + 1);
for(ll i = 1; i < n - 1; i ++)d2[i] = query(i, i + 2);
build_b1(n); build_b2(n);
ll p1, pn;
for(ll i = 1; i <= n; i ++){
if(b1[i] == 1)p1 = i;
if(b1[i] == n)pn = n;
}
if(p1 > pn)
for(ll i = 1; i <= n; i ++)answer(i, b2[i]);
else
for(ll i = 1; i <= n; i ++)answer(i, b1[i]);
}