結果

問題 No.822 Bitwise AND
ユーザー 0214sh70214sh7
提出日時 2019-04-26 22:54:00
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,418 bytes
コンパイル時間 1,372 ms
コンパイル使用メモリ 166,944 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-16 16:09:26
合計ジャッジ時間 2,849 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

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;
    }
    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