結果

問題 No.474 色塗り2
ユーザー 👑 hos.lyrichos.lyric
提出日時 2019-01-19 07:35:01
言語 D
(dmd 2.106.1)
結果
WA  
実行時間 -
コード長 2,101 bytes
コンパイル時間 695 ms
コンパイル使用メモリ 106,584 KB
実行使用メモリ 43,836 KB
最終ジャッジ日時 2023-09-03 22:31:58
合計ジャッジ時間 1,581 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 21 ms
37,064 KB
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 AC 22 ms
36,516 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import std.conv, std.stdio, std.string;
import std.algorithm, std.array, std.bigint, std.container, std.math, std.numeric, std.range, std.regex, std.typecons;
import core.bitop;

class EOFException : Throwable { this() { super("EOF"); } }
string[] tokens;
string readToken() { for (; tokens.empty; ) { if (stdin.eof) { throw new EOFException; } tokens = readln.split; } auto token = tokens.front; tokens.popFront; return token; }
int readInt() { return readToken().to!int; }
long readLong() { return readToken().to!long; }
real readReal() { return readToken().to!real; }

void chmin(T)(ref T t, in T f) { if (t > f) t = f; }
void chmax(T)(ref T t, in T f) { if (t < f) t = f; }

int binarySearch(T)(in T[] as, in bool delegate(T) test) { int low = -1, upp = cast(int)(as.length); for (; low + 1 < upp; ) { int mid = (low + upp) >> 1; (test(as[mid]) ? low : upp) = mid; } return upp; }
int lowerBound(T)(in T[] as, in T val) { return as.binarySearch((T a) => (a < val)); }
int upperBound(T)(in T[] as, in T val) { return as.binarySearch((T a) => (a <= val)); }


// a^-1 (mod 2^64)
long modInv(long a)
in {
  assert(a & 1, "modInv: a must be odd");
}
do {
  long b = ((a << 1) + a) ^ 2;
  b *= 2 - a * b;
  b *= 2 - a * b;
  b *= 2 - a * b;
  b *= 2 - a * b;
  return b;
}


/*
  C * H(C * H(C, B), A)
*/

immutable LIM = 2 * 10^^6 + 10;
long[] facTwo, facOdd;

void main() {
  facTwo = new long[LIM];
  facOdd = new long[LIM];
  facTwo[0] = 0;
  facOdd[0] = 1;
  foreach (i; 1 .. LIM) {
    facTwo[i] = facTwo[i - 1] + bsf(i);
    facOdd[i] = facOdd[i - 1] * (i >> bsf(i));
  }
  
  const numCases = readInt();
  foreach (caseId; 0 .. numCases) {
    const A = readInt();
    const B = readInt();
    const C = readInt();
    
    // binom(C + B - 1, B) mod 2^64
    long p = facOdd[C + B - 1] * modInv(facOdd[C - 1] * facOdd[B]);
    p <<= min(facTwo[C + B - 1] - facTwo[C - 1] - facTwo[B], 64);
    
    p = C * p + A - 1;
    long ans = 1;
    foreach (i; 0 .. bsr(A) + 1) {
      if (!((p >> i) & 1) && ((A >> 1) & 1)) {
        ans = 0;
      }
    }
    (ans *= C) %= 2;
    writeln(ans);
  }
}
0