Submission #915110

# Submission time Handle Problem Language Result Execution time Memory
915110 2024-01-23T11:10:16 Z OAleksa Xylophone (JOI18_xylophone) C++14
0 / 100
1 ms 436 KB
#include "xylophone.h"
#include<bits/stdc++.h>
using namespace std;
const int MAXN = 5069;
int ans[MAXN], vis[MAXN];
void solve(int N) {
  int n = N;
	int l = 2, r = n, mx = 2;
	while (l <= r) {
    int mid = (l + r) / 2;
    if (query(1, mid) == n - 1) {
      mx = mid;
      r = mid - 1;
    }
    else
      l = mid + 1;
	}
	ans[mx] = n;
	vis[n] = 1;
	if (mx < n) {
    int x = query(mx, mx + 1);
    ans[mx + 1] = n - x;
    vis[n - x] = 1;
	}
  int x = query(mx - 1, mx);
  ans[mx - 1] = n - x;
  vis[n - x] = 1;
  for (int i = mx - 2;i >= 1;i--) {
    int x = query(i, i + 1);
    if (ans[i + 1] - x < 1 || vis[ans[i + 1] - x])
      ans[i] = ans[i + 1] + x;
    else if (ans[i + 1] + x > n || vis[ans[i + 1] + x])
      ans[i] = ans[i + 1] - x;
    else {
      int y = query(i, i + 2);
      if (y != x) {
        if (ans[i + 2] > ans[i + 1])
          ans[i] = ans[i + 1] + x;
        else
          ans[i] = ans[i + 1] - x;
      }
      else {
        if (ans[i + 2] > ans[i + 1])
          ans[i] = ans[i + 1] - x;
        else
          ans[i] = ans[i + 1] + x;
      }
    }
    vis[ans[i]] = 1;
  }
  for (int i = mx + 2;i < n;i++) {
    int x = query(i - 1, i);
    if (ans[i - 1] - x < 1 || vis[ans[i - 1] - x])
      ans[i] = ans[i - 1] + x;
    else if (ans[i - 1] + x > n || vis[ans[i - 1] + x])
      ans[i] = ans[i - 1] - x;
    else {
      int y = query(i - 2, i);
      if (y != x) {
        if (ans[i - 2] > ans[i - 1])
          ans[i] = ans[i - 1] + x;
        else
          ans[i] = ans[i - 1] - x;
      }
      else {
        if (ans[i - 2] > ans[i - 1])
          ans[i] = ans[i - 1] - x;
        else
          ans[i] = ans[i - 1] + x;
      }
    }
    vis[ans[i]] = 1;
  }
  for (int i = 1;i <= n;i++) {
    if (!vis[i])
      ans[n] = i;
  }
	for(int i = 1; i <= n; i++) {
		answer(i, ans[i]);
	}
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 436 KB Output is correct
2 Correct 0 ms 436 KB Output is correct
3 Incorrect 1 ms 436 KB Wrong Answer [7]
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 436 KB Output is correct
2 Correct 0 ms 436 KB Output is correct
3 Incorrect 1 ms 436 KB Wrong Answer [7]
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 436 KB Output is correct
2 Correct 0 ms 436 KB Output is correct
3 Incorrect 1 ms 436 KB Wrong Answer [7]
4 Halted 0 ms 0 KB -