結果

問題 No.474 色塗り2
ユーザー 37zigen37zigen
提出日時 2016-12-27 20:31:11
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 1,507 bytes
コンパイル時間 5,438 ms
コンパイル使用メモリ 74,632 KB
実行使用メモリ 169,740 KB
最終ジャッジ日時 2023-08-21 15:38:01
合計ジャッジ時間 8,828 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

package yukicoder;

import java.util.*;

public class Q474 {
	static class Int {
		long v = 0;
		long c = 0;

		public Int(long n) {
			while (n % 2 == 0) {
				n /= 2;
				++c;
			}
			this.v = n;
		}

		public Int() {
		}

		Int mul(Int o) {
			Int i = new Int();
			i.c = this.c + o.c;
			i.v = this.v * o.v % mod;
			return i;
		}

		Int divide(Int o) {
			Int i = new Int();
			i.c = this.c - o.c;
			i.v = this.v * pow(o.v, mod / 2 - 1) % mod;
			return i;
		}

		long toLong() {
			long v = 1l << c;
			v = (v * this.v) % mod;
			return v;
		}
	}

	final static long mod = 1 << 20;

	public static void main(String[] args) {
		Int[] fac = new Int[2000001];
		fac[0] = new Int(1);
		for (int i = 1; i < fac.length; ++i) {
			fac[i] = fac[i - 1].mul(new Int(i));
		}
		Scanner sc = new Scanner(System.in);
		StringBuilder sb = new StringBuilder();
		int T = sc.nextInt();
		while (T-- > 0) {
			int a = sc.nextInt();
			int b = sc.nextInt();
			int c = sc.nextInt();
			if (c % 2 == 0) {
				sb.append("0");
				continue;
			}
			Int x = (new Int(c)).mul(fac[c + b - 1]).divide(fac[b]).divide(fac[c - 1]);
			if (((x.toLong() + a - 1) & a) == a) {
				sb.append("1\n");
			} else {
				sb.append("0\n");
			}
		}
		System.out.println(sb);
	}

	static long pow(long a, long n) {
		long ret = 1;
		for (; n > 0; n >>= 1, a = (a * a) % mod) {
			if (n % 2 == 1)
				ret = (ret * a) % mod;
		}
		return ret;
	}

	static void tr(Object... objects) {
		System.out.println(Arrays.deepToString(objects));
	}
}
0