結果

問題 No.822 Bitwise AND
ユーザー 0214sh70214sh7
提出日時 2019-04-26 23:00:54
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 1,492 bytes
コンパイル時間 1,484 ms
コンパイル使用メモリ 167,676 KB
実行使用メモリ 11,948 KB
最終ジャッジ日時 2023-08-16 16:35:59
合計ジャッジ時間 8,726 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 TLE -
testcase_01 -- -
testcase_02 -- -
testcase_03 -- -
testcase_04 -- -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
//#define MOD 1000000007
#define MOD 998244353
#define INF 100000000000000009
typedef long long ll;
#define REP(i,n) for(int i=0;i<(n);++i)
#define OREP(i,n) for(int i=1;i<=(n);++i)
#define ZREP(i,n) for(int i=1;i<(n);++i)
#define YES(s) s?cout << "YES" << endl:cout << "NO" << endl
#define Yes(s) s?cout << "Yes" << endl:cout << "No" << endl
#define out(s,t,u) s?cout << t << endl:cout << u << endl
#define int ll
#define Endl endl
int V;
int N,K;
vector<int> G;
int B[57];

int saiki(int W,int D){
    //cout << W << " " << D << endl;
    if(W==0){
        if(0<=D && D<K){
            return 1;
        }
        return 0;
    }
    int s=G[W-1];
    int r=0;
    //if(D+s-B[W-1]<=K){
        r+=saiki(W-1,D+s);
    //}
    r+=saiki(W-1,D);
    //if(D-s+B[W-1]>=0){
        r+=saiki(W-1,D-s);
    //}
    return r;
    
}

signed main(){
    cin >> N >> K;
    if(N==0){
        if(K==0){
            cout << 1 << endl;
        }else{
            cout << "INF" << endl;
        }
        return 0;
    }
    int M=N;
    int e=1;
    while(M){
        if(M%2==0){
            G.push_back(e);
        }
        e*=2;
        M/=2;
    }
    G.push_back(2*e);
    G.push_back(4*e);
    G.push_back(8*e);
    V=G.size();
    if(V==0){
        cout << 1 << endl;
        return 0;
    }
    //REP(i,V){cout << G[i] << " ";}
    B[0]=G[0];
    REP(i,V-1){
        B[i+1]=B[i]+G[i+1];
    }
    
    cout << saiki(V,0) << endl;
    
    return 0;
}
0