QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#421130#8724. SeptemberXiaohuba#0 0ms0kbC++144.0kb2024-05-25 13:59:132024-05-25 13:59:14

Judging History

你现在查看的是最新测评结果

  • [2024-05-25 13:59:14]
  • 评测
  • 测评结果:0
  • 用时:0ms
  • 内存:0kb
  • [2024-05-25 13:59:13]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std;

// #define LOCK_GETCHAR
// #define USE_INT_128

#if __cplusplus < 201400
#warning "Please use c++14 or higher."
#define CONSTEXPR_FUNC
#define ENABLE_IF_INT
#else
#define CONSTEXPR_FUNC constexpr
#define ENABLE_IF_INT , enable_if_t<_is_integer<T>, int> = 0
template <class T> constexpr bool _is_integer = numeric_limits<T>::is_integer;
template <> constexpr bool _is_integer<bool> = false;
template <> constexpr bool _is_integer<char> = false;
#ifdef USE_INT_128
template <> constexpr bool _is_integer<__int128> = true;
template <> constexpr bool _is_integer<__uint128_t> = true;
#endif
template <class T ENABLE_IF_INT>
constexpr T INF = numeric_limits<T>::max() >> 1;
#endif

#if !defined(_WIN32) && !defined(LOCK_GETCHAR)
#define getchar getchar_unlocked
#endif

#define il inline
#define mkp make_pair
#define fi first
#define se second
#define For(i, j, k) for (decltype(j - k) i = (j); i <= (k); ++i)     // NOLINT
#define ForDown(i, j, k) for (decltype(j - k) i = (j); i >= (k); --i) // NOLINT
#define pb push_back
#define eb emplace_back
#ifndef ONLINE_JUDGE
#define FileIO(filename)                                                       \
  freopen(filename ".in", "r", stdin);                                         \
  freopen(filename ".out", "w", stdout)
#else
#define FileIO(filename) void(0)
#endif

using ll = long long;
using uint = unsigned int;
using ull = unsigned long long;
using db = double;
using ldb = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
#ifdef USE_INT_128
using lll = __int128_t;
using ulll = __uint128_t;
#endif

// clang-format off
#define lg(x) (31 ^ __builtin_clz((x)))
#define lgll(x) (31ll ^ __builtin_clzll((x)))
template<typename T> constexpr il T sq(const T & x){ return x * x; }
template<typename T> CONSTEXPR_FUNC il void cmin(T & x, const T &y){ x = min(x, y); }
template<typename T> CONSTEXPR_FUNC il void cmax(T & x, const T &y){ x = max(x, y);}
template<typename T> CONSTEXPR_FUNC il T qpow(T x, ull y, T mod){T ans = 1; x %= mod; while (y) { if(y & 1)(ans *= x) %= mod;(x *= x) %= mod; y >>= 1;} return ans;}
template<typename T> CONSTEXPR_FUNC il T qpow(T x, ull y){T ans = 1; while (y) {if(y & 1) ans *= x;x *= x;y >>= 1;} return ans;}
template<typename T ENABLE_IF_INT> il void read(T &x){ x = 0; int f = 1; int c = getchar(); while(!isdigit(c)) {if (c == '-') f = -1;c = getchar();} while(isdigit(c)) {x = x * 10 + c - '0';c = getchar();} x *= f;}
template<typename T, typename ... Args> il void read(T &x, Args &... y){ read(x); read(y...); }
int gcd(int a, int b) { if (!a | !b) return a + b; int az = __builtin_ctz(a); int bz = __builtin_ctz(b); int z = min(az, bz); a >>= az, b >>= bz; while (a != b) { int diff = b - a; az = __builtin_ctz(diff); b = min(a, b), a = abs(diff) >> az; } return a << z; }
ll gcd(ll a, ll b) { if (!a | !b) return a + b; ll az = __builtin_ctzll(a); ll bz = __builtin_ctzll(b); ll z = min(az, bz); a >>= az, b >>= bz; while (a != b) { ll diff = b - a; az = __builtin_ctzll(diff); b = min(a, b), a = abs(diff) >> az; } return a << z; }
// clang-format on

// File head end

namespace {
constexpr int MAXN = 1e5 + 5;
int n, m, sz[MAXN], c[MAXN];
vector<int> T[MAXN];
void dfs(int x) {
  sz[x] = 1;
  for (int v : T[x]) {
    dfs(v);
    sz[x] += sz[v];
  }
}
} // namespace

int solve(int N, int M, std::vector<int> F, std::vector<std::vector<int>> S) {
  n = N, m = M;
  for_each(T, T + n, [&](auto &x) { x.clear(); });
  fill(c, c + n, 0);
  For(i, 1, n - 1) T[F[i]].eb(i);
  dfs(0);
  // For(i, 0, n - 1) cerr << sz[i] << " \n"[i == n - 1];
  int cnt = 0;
  auto upd = [&](int ti) -> bool {
    bool flg = 1;
    For(i, 0, m - 1) {
      flg &= sz[S[i][ti]] == 1;
      if (++c[S[i][ti]] == m)
        sz[F[S[i][ti]]]--;
      else
        flg = 0;
    }
    return flg;
  };
  for (int i = 0; i < n - 1; i++, cnt++) {
    while (!upd(i))
      i++, assert(i < n - 1);
  }
  return cnt;
}

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 0
Runtime Error

Test #1:

score: 0
Runtime Error

input:

txy4h26c1rm1uv8tr3eonahd67u8h56x
4
7 1
0 0 2 3 3 5
1 6 4 3 5 2
10 1
0 1 2 0 3 0 5 4 8
9 7 6 8 4 5 3 2 1
7 1
0 0 0 1 3 0
2 4 1 6 5 3
6 1
0 0 1 1 3
4 5 2 3 1

output:


result:


Subtask #2:

score: 0
Skipped

Dependency #1:

0%

Subtask #3:

score: 0
Runtime Error

Test #17:

score: 0
Runtime Error

input:

txy4h26c1rm1uv8tr3eonahd67u8h56x
53
10 1
0 1 2 3 4 5 6 7 8
9 8 7 6 5 4 3 2 1
10 1
0 1 2 3 4 5 6 7 8
9 7 8 5 6 4 3 2 1
10 1
0 1 2 3 4 5 6 7 8
8 9 7 5 6 3 2 4 1
10 1
0 1 2 3 4 5 6 7 8
8 9 6 7 5 4 3 2 1
10 1
0 1 2 3 4 5 6 7 8
8 9 7 5 6 3 4 2 1
10 1
0 1 2 3 4 5 6 7 8
9 8 7 6 5 4 2 3 1
10 1
0 1 2 3 4 5 6...

output:


result:


Subtask #4:

score: 0
Skipped

Dependency #1:

0%

Subtask #5:

score: 0
Skipped

Dependency #3:

0%

Subtask #6:

score: 0
Skipped

Dependency #1:

0%

Subtask #7:

score: 0
Skipped

Dependency #3:

0%

Subtask #8:

score: 0
Skipped

Dependency #1:

0%

Subtask #9:

score: 0
Skipped

Dependency #3:

0%

Subtask #10:

score: 0
Skipped

Dependency #1:

0%