Submission #795213

# Submission time Handle Problem Language Result Execution time Memory
795213 2023-07-27T07:33:16 Z arush_agu Xylophone (JOI18_xylophone) C++17
47 / 100
117 ms 98160 KB
#include "xylophone.h"
#include <algorithm>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>

#ifdef DEBUG
#include <time.h>
#endif

#define all(a) (a).begin(), (a).end()
#define rev(a) (a).rbegin(), (a).rend()
#define F first
#define S second
int recur_depth = 0;
#ifdef DEBUG
#define dbg(x)                                                                 \
  {                                                                            \
    ++recur_depth;                                                             \
    auto x_ = x;                                                               \
    --recur_depth;                                                             \
    cerr << string(recur_depth, '\t') << "\e[91m" << __func__ << ":"           \
         << __LINE__ << "\t" << #x << " = " << x_ << "\e[39m" << endl;         \
  }
#else
#define dbg(x)
#endif

using namespace std;
using namespace __gnu_pbds;

typedef pair<int, int> ii;

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> llll;

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pair<int, int>> vii;
typedef vector<vii> vvii;

typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<pair<ll, ll>> vll;
typedef vector<vll> vvll;

typedef vector<bool> vb;

template <class type1>
using ordered_set = tree<type1, null_type, less<type1>, rb_tree_tag,
                         tree_order_statistics_node_update>;

template <typename A, typename B>
ostream &operator<<(ostream &os, const pair<A, B> &p) {
  return os << '(' << p.first << ", " << p.second << ')';
}
template <typename T_container, typename T = typename enable_if<
                                    !is_same<T_container, string>::value,
                                    typename T_container::value_type>::type>
ostream &operator<<(ostream &os, const T_container &v) {
  os << '{';
  string sep;
  for (const T &x : v)
    os << sep << x, sep = ", ";
  return os << '}';
}

const ll MOD = 1e9 + 7;
// const ll MOD = 998244353;
const ll INF = 1e9;
const ld EPS = 1e-9;

static int A[5000];

void solve(int N) {
  vvi q(N + 1, vi(N + 1, -1));
  int cnt = 0;
  auto ask = [&](int s, int t) {
    if (q[s][t] != -1)
      return q[s][t];
    cnt++;
    return q[s][t] = query(s, t);
  };

  vi ans(N + 1, -1);
  vi at(N + 1, -1);

  int tot = ask(1, N);
  int l = 2, r = N - 1, pos_n = N;
  while (l <= r) {
    int mid = (l + r) / 2;
    if (ask(1, mid) != tot)
      l = mid + 1;
    else {
      pos_n = mid;
      r = mid - 1;
    }
  }

  l = 2, r = pos_n - 1;
  int pos_1 = 1;
  while (l <= r) {
    int mid = (l + r) / 2;
    if (ask(mid, pos_n) != tot)
      r = mid - 1;
    else {
      pos_1 = mid;
      l = mid + 1;
    }
  }

  auto in_rng = [&](int x) { return 1 <= x && x <= N; };
  auto fill_place = [&](int pos, int v) {
    ans[v] = pos;
    at[pos] = v;
  };

  fill_place(pos_1, 1), fill_place(pos_n, N);
  at[pos_1] = 1, at[pos_n] = N;
  if (pos_1 + 1 < pos_n) {
    fill_place(pos_1 + 1, 1 + ask(pos_1, pos_1 + 1));

    for (int i = pos_1 + 2; i < pos_n; i++) {
      int ab = ask(i - 2, i - 1), bc = ask(i - 1, i), ac = ask(i - 2, i);
      if (ac == ab || ac == bc) {
        if (at[i - 2] < at[i - 1])
          fill_place(i, at[i - 1] - bc);
        else
          fill_place(i, at[i - 1] + bc);
      } else {
        if (at[i - 2] < at[i - 1])
          fill_place(i, at[i - 1] + bc);
        else
          fill_place(i, at[i - 1] - bc);
      }
    }
  }

  if (pos_n < N) {
    fill_place(pos_n + 1, N - ask(pos_n, pos_n + 1));
    for (int i = pos_n + 2; i <= N; i++) {
      int ab = ask(i - 2, i - 1), bc = ask(i - 1, i), ac = ask(i - 2, i);
      if (ac == ab || ac == bc) {
        if (at[i - 2] < at[i - 1])
          fill_place(i, at[i - 1] - bc);
        else
          fill_place(i, at[i - 1] + bc);
      } else {
        if (at[i - 2] < at[i - 1])
          fill_place(i, at[i - 1] + bc);
        else
          fill_place(i, at[i - 1] - bc);
      }
    }
  }

  if (pos_1 > 1) {
    fill_place(pos_1 - 1, 1 + ask(pos_1 - 1, pos_1));
    for (int i = pos_1 - 2; i >= 1; i--) {
      int ab = ask(i, i + 1), bc = ask(i + 1, i + 2), ac = ask(i, i + 2);
      if (ac == bc || ac == ab) {
        if (at[i + 1] < at[i + 2])
          fill_place(i, at[i + 1] + ab);
        else
          fill_place(i, at[i + 1] - ab);
      } else {
        if (at[i + 1] < at[i + 2])
          fill_place(i, at[i + 1] - ab);
        else
          fill_place(i, at[i + 1] + ab);
      }
    }
  }

  for (int i = 1; i <= N; i++)
    answer(i, at[i]);
}

Compilation message

xylophone.cpp: In function 'void solve(int)':
xylophone.cpp:132:8: warning: variable 'in_rng' set but not used [-Wunused-but-set-variable]
  132 |   auto in_rng = [&](int x) { return 1 <= x && x <= N; };
      |        ^~~~~~
xylophone.cpp: At global scope:
xylophone.cpp:93:12: warning: 'A' defined but not used [-Wunused-variable]
   93 | static int A[5000];
      |            ^
# Verdict Execution time Memory Grader output
1 Correct 0 ms 208 KB Output is correct
2 Correct 0 ms 208 KB Output is correct
3 Correct 1 ms 208 KB Output is correct
4 Correct 2 ms 336 KB Output is correct
5 Correct 2 ms 336 KB Output is correct
6 Correct 3 ms 336 KB Output is correct
7 Correct 2 ms 336 KB Output is correct
8 Correct 1 ms 336 KB Output is correct
9 Correct 3 ms 336 KB Output is correct
10 Correct 2 ms 336 KB Output is correct
11 Correct 2 ms 336 KB Output is correct
12 Correct 2 ms 336 KB Output is correct
13 Correct 2 ms 336 KB Output is correct
14 Correct 2 ms 336 KB Output is correct
15 Correct 2 ms 336 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 208 KB Output is correct
2 Correct 0 ms 208 KB Output is correct
3 Correct 1 ms 208 KB Output is correct
4 Correct 2 ms 336 KB Output is correct
5 Correct 2 ms 336 KB Output is correct
6 Correct 3 ms 336 KB Output is correct
7 Correct 2 ms 336 KB Output is correct
8 Correct 1 ms 336 KB Output is correct
9 Correct 3 ms 336 KB Output is correct
10 Correct 2 ms 336 KB Output is correct
11 Correct 2 ms 336 KB Output is correct
12 Correct 2 ms 336 KB Output is correct
13 Correct 2 ms 336 KB Output is correct
14 Correct 2 ms 336 KB Output is correct
15 Correct 2 ms 336 KB Output is correct
16 Correct 4 ms 464 KB Output is correct
17 Correct 9 ms 1104 KB Output is correct
18 Correct 15 ms 2896 KB Output is correct
19 Correct 15 ms 4236 KB Output is correct
20 Correct 17 ms 4248 KB Output is correct
21 Correct 17 ms 4176 KB Output is correct
22 Correct 20 ms 4176 KB Output is correct
23 Correct 13 ms 4192 KB Output is correct
24 Correct 19 ms 4176 KB Output is correct
25 Correct 18 ms 4176 KB Output is correct
26 Correct 17 ms 4240 KB Output is correct
27 Correct 15 ms 4176 KB Output is correct
28 Correct 20 ms 4176 KB Output is correct
29 Correct 10 ms 4176 KB Output is correct
30 Correct 19 ms 4176 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 208 KB Output is correct
2 Correct 0 ms 208 KB Output is correct
3 Correct 1 ms 208 KB Output is correct
4 Correct 2 ms 336 KB Output is correct
5 Correct 2 ms 336 KB Output is correct
6 Correct 3 ms 336 KB Output is correct
7 Correct 2 ms 336 KB Output is correct
8 Correct 1 ms 336 KB Output is correct
9 Correct 3 ms 336 KB Output is correct
10 Correct 2 ms 336 KB Output is correct
11 Correct 2 ms 336 KB Output is correct
12 Correct 2 ms 336 KB Output is correct
13 Correct 2 ms 336 KB Output is correct
14 Correct 2 ms 336 KB Output is correct
15 Correct 2 ms 336 KB Output is correct
16 Correct 4 ms 464 KB Output is correct
17 Correct 9 ms 1104 KB Output is correct
18 Correct 15 ms 2896 KB Output is correct
19 Correct 15 ms 4236 KB Output is correct
20 Correct 17 ms 4248 KB Output is correct
21 Correct 17 ms 4176 KB Output is correct
22 Correct 20 ms 4176 KB Output is correct
23 Correct 13 ms 4192 KB Output is correct
24 Correct 19 ms 4176 KB Output is correct
25 Correct 18 ms 4176 KB Output is correct
26 Correct 17 ms 4240 KB Output is correct
27 Correct 15 ms 4176 KB Output is correct
28 Correct 20 ms 4176 KB Output is correct
29 Correct 10 ms 4176 KB Output is correct
30 Correct 19 ms 4176 KB Output is correct
31 Correct 38 ms 18724 KB Output is correct
32 Correct 60 ms 37740 KB Output is correct
33 Correct 82 ms 74736 KB Output is correct
34 Incorrect 117 ms 98160 KB Wrong Answer [2]
35 Halted 0 ms 0 KB -