# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
759542 | otarius | Xylophone (JOI18_xylophone) | C++17 | 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 "Xylophone.h"
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <cstring>
#include <queue>
#include <map>
#include <cmath>
#include <iomanip>
using namespace std;
#define ff first
#define sc second
#define pb push_back
#define ll long long
#define pll pair<ll, ll>
#define pii pair <int, int>
#define ull unsigned long long
// #define int long long
// #define int unsigned long long
const ll inf = 1e9 + 7;
const ll weirdMod = 998244353;
bool check(vector<int> v, int n) {
set<int> st;
for (int u : v)
st.insert(u);
if (st.size() != n)
return false;
int cur = 1;
for (int u : st) {
if (cur == u)
cur++;
else return false;
} return true;
}
void solve(int n) {
int b[n + 1], c[n + 1];
for (int i = 1; i <= n - 1; i++)
b[i] = query(i, i + 1);
for (int i = 1; i <= n - 2; i++)
c[i] = query(i, i + 2);
bool flg[n + 1];
/*
flg[i] = 1, if a[i] > a[i + 1]
flg[i] = 0, if a[i] < a[i + 1]
*/ flg[1] = 1;
for (int i = 2; i <= n - 1; i++) {
if (b[i - 1] + b[i] == c[i - 1])
flg[i] = flg[i - 1];
else flg[i] = !flg[i - 1];
} int cur = 1, mn = 1; vector<int> a;
for (int i = 2; i <= n; i++) {
if (flg[i - 1] == 1) {
cur -= b[i - 1];
a.pb(cur); mn = min(mn, cur);
} else {
cur += b[i - 1];
a.pb(cur); mn = min(mn, cur);
}
} for (int &v : a)
v += -mn + 1;
if (check(a, n)) {
for (int i = 0; i < a.size(); i++)
answer(i + 1, a[i]);
return;
} cur = 1; mn = 1; a.clear();
for (int i = 2; i <= n; i++) {
if (flg[i - 1] == 1) {
cur += b[i - 1];
a.pb(cur); mn = min(mn, cur);
} else {
cur += b[i - 1];
a.pb(cur); mn = min(mn, cur);
}
} for (int &v : a)
v += -mn + 1;
for (int i = 0; i < a.size(); i++)
answer(i + 1, a[i]);
}