結果

問題 No.822 Bitwise AND
ユーザー ttttan2ttttan2
提出日時 2019-04-26 22:24:12
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 22 ms / 2,000 ms
コード長 1,292 bytes
コンパイル時間 2,586 ms
コンパイル使用メモリ 146,128 KB
実行使用メモリ 35,248 KB
最終ジャッジ日時 2023-09-08 01:09:50
合計ジャッジ時間 3,154 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 21 ms
34,916 KB
testcase_01 AC 21 ms
34,904 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 1 ms
4,384 KB
testcase_04 AC 19 ms
34,968 KB
testcase_05 AC 18 ms
35,024 KB
testcase_06 AC 19 ms
35,132 KB
testcase_07 AC 19 ms
34,900 KB
testcase_08 AC 19 ms
34,904 KB
testcase_09 AC 19 ms
34,904 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 2 ms
4,384 KB
testcase_12 AC 19 ms
35,248 KB
testcase_13 AC 1 ms
4,380 KB
testcase_14 AC 2 ms
4,380 KB
testcase_15 AC 19 ms
35,072 KB
testcase_16 AC 22 ms
34,916 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<pii,int> ppii;
typedef pair<ll,ll> pll;
typedef tuple<ll,ll,ll> tl;
ll mod=1000000007;
ll gcd(ll a,ll b){
  if(a<b)swap(a,b);
  if(a%b==0)return b;
  return gcd(b,a%b);
}
ll lcm(ll a,ll b){
  ll ret=a*b;
  ll u=gcd(a,b);
  return ret/u;
}
int main(){
  ll n,k;cin>>n>>k;
  ll u;
  if(n==0){
    if(k==0)cout<<1<<endl;
    else cout<<"INF"<<endl;
    return 0;
  }
  if(k==0){
    cout<<1<<endl;
    return 0;
  }
  for(int i=0;;i++){
    if(pow(2,i)>n){
      u=i;
      break;
    }
  }
  ll q=pow(2,u)-1;
  ll e=n+pow(2,u);
  if(e-q<=k){
    cout<<"INF"<<endl;
    return 0;
  }
  ll dp[20][200000];
  for(int i=0;i<20;i++)fill(dp[i],dp[i]+200000,0);
  dp[0][0]=1;
  if(n%2==0){
    dp[0][1]=2;
  }
  for(int i=0;i<19;i++){
    ll p=pow(2,i+1);
    ll y=n/p;
    for(int j=0;j<200000;j++){
      dp[i+1][j]+=dp[i][j];
      if(y%2==1)continue;
      if(j+p<200000){
        dp[i+1][j+p]+=dp[i][j];
      }
      if(p-j<200000&&p-j>=0){
        dp[i+1][p-j]+=dp[i][j];
      }
    }
  }
  ll ans=1;
  ll sum=0;
  for(int i=1;i<=k;i++){
    sum+=dp[19][i];
  }
  cout<<ans+sum/2<<endl;
  //for(int i=0;i<u;i++){
    //for(int j=0;j<=k;j++)cout<<dp[i][j]<<" ";
    //cout<<endl;
 // }
}
0