이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#include "xylophone.h"
#define ll long long
#define ld long double
#define sp ' '
#define en '\n'
#define smin(a, b) a = min(a, b)
#define smax(a, b) a = max(a, b)
using namespace std;
void solve(int n) {
vector<int> a(n);
for (int i = 1; i < n; i++) {
a[i] = query(i, i + 1);
}
vector<bool> b(n - 1);
for (int i = 1; i < n - 1; i++) {
int x = query(i, i + 2);
if (x == a[i] + a[i + 1]) b[i] = 1;
}
vector<int> ans(n + 1);
auto Can = [&] (int x) {
ans[x] = 1;
int tr = 1;
int up = 1;
for (int i = x - 1; i >= 1; i--) {
if (i == x - 1) {
tr += a[i];
ans[i] = tr;
continue;
}
if (b[i] == 0) up ^= 1;
if (up == 1) tr += a[i];
else tr -= a[i];
ans[i] = tr;
}
tr = 1;
up = 1;
for (int i = x + 1; i <= n; i++) {
if (i == x + 1) {
tr += a[i - 1];
ans[i] = tr;
continue;
}
if (b[i - 2] == 0) up ^= 1;
if (up == 1) tr += a[i - 1];
else tr -= a[i - 1];
ans[i] = tr;
}
bool p = 0;
for (int i = 1; i <= n; i++) {
if (ans[i] <= 0) return false;
if (i > x && ans[i] == n) p = 1;
}
return p;
};
for (int i = 1; i <= n; i++) {
if (Can(i)) {
for (int j = 1; j <= n; j++) answer(j, ans[j]);
return;
}
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |