結果

問題 No.1665 quotient replace
ユーザー tnakao0123tnakao0123
提出日時 2021-09-04 20:37:04
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 1,858 ms / 3,000 ms
コード長 1,269 bytes
コンパイル時間 705 ms
コンパイル使用メモリ 93,692 KB
実行使用メモリ 7,560 KB
最終ジャッジ日時 2023-08-23 11:58:49
合計ジャッジ時間 29,270 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 5 ms
7,372 KB
testcase_01 AC 4 ms
7,260 KB
testcase_02 AC 4 ms
7,404 KB
testcase_03 AC 9 ms
7,332 KB
testcase_04 AC 10 ms
7,328 KB
testcase_05 AC 5 ms
7,372 KB
testcase_06 AC 50 ms
7,440 KB
testcase_07 AC 13 ms
7,492 KB
testcase_08 AC 30 ms
7,284 KB
testcase_09 AC 157 ms
7,376 KB
testcase_10 AC 1,018 ms
7,344 KB
testcase_11 AC 1,620 ms
7,400 KB
testcase_12 AC 361 ms
7,376 KB
testcase_13 AC 1,848 ms
7,284 KB
testcase_14 AC 1,854 ms
7,412 KB
testcase_15 AC 1,849 ms
7,560 KB
testcase_16 AC 1,851 ms
7,496 KB
testcase_17 AC 1,858 ms
7,288 KB
testcase_18 AC 4 ms
7,284 KB
testcase_19 AC 4 ms
7,284 KB
testcase_20 AC 4 ms
7,528 KB
testcase_21 AC 4 ms
7,268 KB
testcase_22 AC 4 ms
7,408 KB
testcase_23 AC 4 ms
7,400 KB
testcase_24 AC 4 ms
7,328 KB
testcase_25 AC 4 ms
7,352 KB
testcase_26 AC 9 ms
7,396 KB
testcase_27 AC 20 ms
7,344 KB
testcase_28 AC 66 ms
7,268 KB
testcase_29 AC 111 ms
7,288 KB
testcase_30 AC 237 ms
7,260 KB
testcase_31 AC 269 ms
7,276 KB
testcase_32 AC 1,581 ms
7,344 KB
testcase_33 AC 877 ms
7,372 KB
testcase_34 AC 1,409 ms
7,384 KB
testcase_35 AC 1,343 ms
7,264 KB
testcase_36 AC 1,377 ms
7,376 KB
testcase_37 AC 1,303 ms
7,412 KB
testcase_38 AC 1,458 ms
7,416 KB
testcase_39 AC 1,174 ms
7,416 KB
testcase_40 AC 1,174 ms
7,496 KB
testcase_41 AC 1,171 ms
7,284 KB
testcase_42 AC 4 ms
7,336 KB
testcase_43 AC 4 ms
7,408 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

/* -*- coding: utf-8 -*-
 *
 * 1665.cc:  No.1665 quotient replace - yukicoder
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<bitset>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

const int MAX_N = 1000000;
const int MAX_A = 1000000;
const int MAX_G = 240;

/* typedef */

typedef bitset<MAX_G> bts;

/* global variables */

int cache[MAX_A + 1];

/* subroutines */

int grundy(int a) {
  if (cache[a] >= 0) return cache[a];

  bts bs;
  for (int p = 1; p * p <= a; p++)
    if (a % p == 0) {
      bs.set(grundy(p));
      int q = a / p;
      if (q < a && q != p) bs.set(grundy(q));
    }

  int g = 1;
  for (; bs.test(g); g++);
  return (cache[a] = g);
}

/* main */

int main() {
  memset(cache, -1, sizeof(cache));
  cache[0] = cache[1] = 0;

  int n;
  scanf("%d", &n);

  int nim = 0;
  for (int i = 0; i < n; i++) {
    int ai;
    scanf("%d", &ai);
    //printf("grundy(%d) = %d\n", ai, grundy(ai));
    nim ^= grundy(ai);
  }

  if (nim) puts("white");
  else puts("black");
  return 0;
}

0