結果

問題 No.822 Bitwise AND
ユーザー kimiyukikimiyuki
提出日時 2019-04-26 21:54:03
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 1,751 ms / 2,000 ms
コード長 883 bytes
コンパイル時間 1,942 ms
コンパイル使用メモリ 198,612 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-08 01:08:58
合計ジャッジ時間 21,859 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1,703 ms
4,380 KB
testcase_01 AC 29 ms
4,376 KB
testcase_02 AC 8 ms
4,380 KB
testcase_03 AC 12 ms
4,376 KB
testcase_04 AC 1,728 ms
4,376 KB
testcase_05 AC 806 ms
4,380 KB
testcase_06 AC 1,468 ms
4,380 KB
testcase_07 AC 1,751 ms
4,380 KB
testcase_08 AC 1,528 ms
4,376 KB
testcase_09 AC 1,263 ms
4,384 KB
testcase_10 AC 1,389 ms
4,380 KB
testcase_11 AC 1,504 ms
4,380 KB
testcase_12 AC 1,507 ms
4,380 KB
testcase_13 AC 9 ms
4,376 KB
testcase_14 AC 1,512 ms
4,376 KB
testcase_15 AC 963 ms
4,376 KB
testcase_16 AC 12 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; (i) < (int)(n); ++ (i))
#define REP3(i, m, n) for (int i = (m); (i) < (int)(n); ++ (i))
#define REP_R(i, n) for (int i = (int)(n) - 1; (i) >= 0; -- (i))
#define REP3R(i, m, n) for (int i = (int)(n) - 1; (i) >= (int)(m); -- (i))
#define ALL(x) begin(x), end(x)
using ll = long long;
using namespace std;

ll solve(ll n, ll k) {
    ll cnt = 0;
    REP (x, 8 * n + 3) {
        REP3 (y, x, x + k + 1) {
            cnt += ((x & y) == n);
        }
    }
    ll cnt1 = 0;
    REP (x, 5000000) {
        REP3 (y, x, x + k + 1) {
            cnt1 += ((x & y) == n);
        }
    }
    if (cnt1 > cnt) return LLONG_MAX;
    return cnt;
}

int main() {
    ll n, k; cin >> n >> k;
    ll cnt = solve(n, k);
    if (cnt == LLONG_MAX) {
        cout << "INF" << endl;
    } else {
        cout << cnt << endl;
    }
    return 0;
}
0