제출 #548198

#제출 시각아이디문제언어결과실행 시간메모리
548198Alex_tz307Xylophone (JOI18_xylophone)C++17
100 / 100
99 ms336 KiB
#include <bits/stdc++.h>
#include "xylophone.h"

using namespace std;

void solve(int n) {
  vector<int> a(n), d(n);
  for (int i = 0; i < n - 1; ++i) {
    d[i] = query(i + 1, i + 2);
  }
  int sgn = 1;
  a[0] = 0;
  a[1] = d[0];
  for (int i = 1; i < n - 1; ++i) {
    if (query(i, i + 2) != d[i - 1] + d[i]) {
      sgn = -sgn;
    }
    a[i + 1] = a[i] + sgn * d[i];
  }
  int posMin = 0, posMax = 0;
  for (int i = 1; i < n; ++i) {
    if (a[i] < a[posMin]) {
      posMin = i;
    }
    if (a[posMax] < a[i]) {
      posMax = i;
    }
  }
  if (posMax < posMin) {
    for (int i = 1; i < n; ++i) {
      a[i] = -a[i];
    }
    swap(posMin, posMax);
  }
  for (int i = 0; i < n; ++i) {
    answer(i + 1, a[i] - a[posMin] + 1);
  }
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...