結果

問題 No.1665 quotient replace
ユーザー 👑 emthrmemthrm
提出日時 2021-09-03 21:31:25
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 312 ms / 3,000 ms
コード長 2,170 bytes
コンパイル時間 2,352 ms
コンパイル使用メモリ 208,656 KB
実行使用メモリ 15,452 KB
最終ジャッジ日時 2024-05-09 01:55:34
合計ジャッジ時間 8,733 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 1 ms
5,376 KB
testcase_03 AC 11 ms
11,308 KB
testcase_04 AC 12 ms
11,312 KB
testcase_05 AC 12 ms
11,288 KB
testcase_06 AC 15 ms
11,376 KB
testcase_07 AC 11 ms
11,412 KB
testcase_08 AC 14 ms
11,356 KB
testcase_09 AC 21 ms
11,424 KB
testcase_10 AC 114 ms
12,672 KB
testcase_11 AC 236 ms
14,260 KB
testcase_12 AC 38 ms
11,628 KB
testcase_13 AC 312 ms
15,452 KB
testcase_14 AC 307 ms
15,212 KB
testcase_15 AC 308 ms
15,436 KB
testcase_16 AC 309 ms
15,212 KB
testcase_17 AC 301 ms
15,264 KB
testcase_18 AC 8 ms
7,680 KB
testcase_19 AC 6 ms
6,016 KB
testcase_20 AC 9 ms
8,192 KB
testcase_21 AC 10 ms
8,704 KB
testcase_22 AC 6 ms
6,656 KB
testcase_23 AC 11 ms
9,808 KB
testcase_24 AC 8 ms
7,680 KB
testcase_25 AC 6 ms
6,528 KB
testcase_26 AC 12 ms
11,320 KB
testcase_27 AC 12 ms
11,340 KB
testcase_28 AC 20 ms
11,564 KB
testcase_29 AC 23 ms
11,576 KB
testcase_30 AC 91 ms
13,292 KB
testcase_31 AC 129 ms
14,352 KB
testcase_32 AC 227 ms
14,188 KB
testcase_33 AC 95 ms
12,364 KB
testcase_34 AC 195 ms
13,584 KB
testcase_35 AC 171 ms
13,512 KB
testcase_36 AC 183 ms
13,496 KB
testcase_37 AC 166 ms
13,288 KB
testcase_38 AC 199 ms
13,704 KB
testcase_39 AC 143 ms
13,084 KB
testcase_40 AC 140 ms
13,052 KB
testcase_41 AC 144 ms
12,972 KB
testcase_42 AC 2 ms
5,376 KB
testcase_43 AC 2 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,m,n) for(int i=(m);i<(n);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
using ll = long long;
constexpr int INF = 0x3f3f3f3f;
constexpr long long LINF = 0x3f3f3f3f3f3f3f3fLL;
constexpr double EPS = 1e-8;
constexpr int MOD = 1000000007;
// constexpr int MOD = 998244353;
constexpr int dy[] = {1, 0, -1, 0}, dx[] = {0, -1, 0, 1};
constexpr int dy8[] = {1, 1, 0, -1, -1, -1, 0, 1}, dx8[] = {0, -1, -1, -1, 0, 1, 1, 1};
template <typename T, typename U> inline bool chmax(T &a, U b) { return a < b ? (a = b, true) : false; }
template <typename T, typename U> inline bool chmin(T &a, U b) { return a > b ? (a = b, true) : false; }
struct IOSetup {
  IOSetup() {
    std::cin.tie(nullptr);
    std::ios_base::sync_with_stdio(false);
    std::cout << fixed << setprecision(20);
  }
} iosetup;

std::vector<int> prime_sieve(int n, bool get_only_prime) {
  std::vector<int> prime, smallest_prime_factor(n + 1);
  std::iota(smallest_prime_factor.begin(), smallest_prime_factor.end(), 0);
  for (int i = 2; i <= n; ++i) {
    if (smallest_prime_factor[i] == i) prime.emplace_back(i);
    for (int p : prime) {
      if (i * p > n || p > smallest_prime_factor[i]) break;
      smallest_prime_factor[i * p] = p;
    }
  }
  return get_only_prime ? prime : smallest_prime_factor;
}

struct osa_k {
  std::vector<int> smallest_prime_factor;

  osa_k(int n = 10000000) : smallest_prime_factor(prime_sieve(n, false)) {}

  std::vector<std::pair<int, int>> query(int n) const {
    std::vector<std::pair<int, int>> res;
    while (n > 1) {
      int prime = smallest_prime_factor[n], exponent = 0;
      while (smallest_prime_factor[n] == prime) {
        ++exponent;
        n /= prime;
      }
      res.emplace_back(prime, exponent);
    }
    return res;
  }
};

int main() {
  int n; cin >> n;
  vector<int> a(n); REP(i, n) cin >> a[i];
  osa_k osa(*max_element(ALL(a)));
  int x = 0;
  for (int ai : a) {
    int grundy = 0;
    for (auto [_, num] : osa.query(ai)) {
      grundy += num;
    }
    x ^= grundy;
  }
  cout << (x == 0 ? "black\n" : "white\n");
  return 0;
}
0