結果
問題 | No.474 色塗り2 |
ユーザー |
|
提出日時 | 2016-12-24 04:05:01 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
TLE
|
実行時間 | - |
コード長 | 1,806 bytes |
コンパイル時間 | 894 ms |
コンパイル使用メモリ | 72,336 KB |
実行使用メモリ | 14,372 KB |
最終ジャッジ日時 | 2024-12-14 17:13:08 |
合計ジャッジ時間 | 4,693 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 |
other | AC * 3 TLE * 1 |
ソースコード
#include <iostream>#include <array>#include <tuple>#include <cassert>#define repeat(i,n) for (int i = 0; (i) < int(n); ++(i))typedef long long ll;using namespace std;ll powmod(ll x, ll y, ll p) { // O(log y)assert (y >= 0);x %= p; if (x < 0) x += p;ll z = 1;for (ll i = 1; i <= y; i <<= 1) {if (y & i) z = z * x % p;x = x * x % p;}return z;}const int A_MAX = 1000000;const int MOD = 1048576; // pow(2, floor(log2(A_MAX)) + 1);int invmod(int n) {static array<int, MOD> memo = {};assert (n % 2 == 1);if (not memo[n]) memo[n] = powmod(n, MOD/2-1, MOD);return memo[n];}pair<int, int> split(int x) {if (x == 0) return make_pair(0, 0);int ctz = __builtin_ctz(x);return make_pair(x >> ctz, ctz);}pair<int, int> inv(pair<int, int> it) {int frac, expo; tie(frac, expo) = it;return make_pair(invmod(frac), - expo);}pair<int, int> mult(pair<int, int> a, pair<int, int> b) {int a_frac, a_expo; tie(a_frac, a_expo) = a;int b_frac, b_expo; tie(b_frac, b_expo) = b;return make_pair(a_frac *(ll) b_frac % MOD, a_expo + b_expo);}int merge(pair<int, int> it) {int frac, expo; tie(frac, expo) = it;assert (expo >= 0);while (expo --) frac = frac * 2 % MOD;return frac;}int choose_modulo(int n, int r) {pair<int, int> acc = split(1);repeat (i,r) acc = mult(acc, mult(split(n-i), inv(split(i+1))));return merge(acc);}bool solve(int a, int b, int c) {assert (a <= A_MAX);if (c % 2 == 0) return 0;ll d = c *(ll) choose_modulo(c+b-1, b) % MOD + MOD;return choose_modulo(d+a-1, a) % 2;}int main() {int t; cin >> t;while (t --) {int a, b, c; cin >> a >> b >> c;cout << solve(a, b, c) << endl;}return 0;}