結果

問題 No.474 色塗り2
ユーザー snukesnuke
提出日時 2016-12-19 02:18:04
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 86 ms / 2,000 ms
コード長 1,601 bytes
コンパイル時間 1,373 ms
コンパイル使用メモリ 160,228 KB
実行使用メモリ 36,444 KB
最終ジャッジ日時 2024-05-08 11:01:06
合計ジャッジ時間 2,069 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 21 ms
36,184 KB
testcase_01 AC 20 ms
36,428 KB
testcase_02 AC 21 ms
36,444 KB
testcase_03 AC 86 ms
36,392 KB
testcase_04 AC 21 ms
36,356 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:45:8: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   45 |   scanf("%d",&ts);
      |   ~~~~~^~~~~~~~~~
main.cpp:56:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   56 |     scanf("%d%d%d",&a,&b,&c);
      |     ~~~~~^~~~~~~~~~~~~~~~~~~

ソースコード

diff #

#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define fi first
#define se second
using namespace std;
typedef long long int ll;

// mod
const int K = 20;
const int mod = 1<<K;
struct mint {
  ll x;
  mint():x(0){}
  mint(ll x):x((x%mod+mod)%mod){}
  mint& operator+=(const mint& a){ if((x+=a.x)>=mod) x-=mod; return *this;}
  mint& operator-=(const mint& a){ if((x+=mod-a.x)>=mod) x-=mod; return *this;}
  mint& operator*=(const mint& a){ (x*=a.x)%=mod; return *this;}
  mint operator+(const mint& a)const{ return mint(*this) += a;}
  mint operator-(const mint& a)const{ return mint(*this) -= a;}
  mint operator*(const mint& a)const{ return mint(*this) *= a;}
};
mint ex(mint a, ll t) {
  if(!t) return 1;
  mint res = ex(a,t/2);
  res *= res;
  return (t&1)?res*a:res;
}
//

typedef pair<mint,int> P;
P p[mod*2];

mint inv(mint a) { return ex(a,mod/2-1);}
mint comb(int a, int b) {
  int c = a-b;
  int two = p[a].se-p[b].se-p[c].se;
  if (two >= K) return 0;
  mint res = p[a].fi*inv(p[b].fi)*inv(p[c].fi);
  res *= 1<<two;
  return res;
}

int main() {
  int ts;
  scanf("%d",&ts);
  assert(1 <= ts && ts <= 100000);
  p[0] = P(1,0);
  rep(i,mod*2) if (i) {
    p[i] = p[i-1];
    int x = i;
    while (x%2 == 0) p[i].se++, x >>= 1;
    p[i].fi *= x;
  }
  rep(ti,ts) {
    int a,b,c;
    scanf("%d%d%d",&a,&b,&c);
    assert(1 <= a && a <= 1000000);
    assert(1 <= b && b <= 1000000);
    assert(1 <= c && c <= 1000000);
    // C(C(c+b-1,b)*c+a-1,a)*c
    mint x = comb(c+b-1,b)*c;
    x = x+a-1;
    int ans = ((x.x&a)==a)&c;
    printf("%d\n", ans);
  }
  return 0;
}
0