제출 #516094

#제출 시각아이디문제언어결과실행 시간메모리
516094lovrotXylophone (JOI18_xylophone)C++11
100 / 100
109 ms412 KiB
#include <bits/stdc++.h>
#include "xylophone.h"
using namespace std;
 
int const N = 5005;
 
int a[N];
 
void solve(int n) {
  for (int i = 0; i + 1 < n; ++i) {
    a[i+1] = query(i + 1, i + 2);
  }
  for (int i = 0; i + 2 < n; ++i) {
    int t = query(i + 1, i + 3);
    if (t == abs(a[i+1]) + abs(a[i+2])) {
      if (a[i+1] < 0) a[i+2] *= -1;
    } else {
      if (a[i+1] > 0) a[i+2] *= -1;
    }
  }
  partial_sum(a, a + n, a);
  int mn = *min_element(a, a + n);
  int sw = 0;
  for (int i = 0; i < n; ++i) {
    a[i] -= mn - 1;
    if (sw == 0) {
      if (a[i] == 1) sw = -1;
      else if (a[i] == n) sw = 1;
    }
  }
  if (sw == 1) {
    for (int i = 0; i < n; ++i) {
      a[i] = n - a[i] + 1;
    }
  }
  for (int i = 0; i < n; ++i) {
    answer(i + 1, a[i]);
  }
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...