結果

問題 No.2071 Shift and OR
ユーザー tokumini_sstokumini_ss
提出日時 2022-09-16 21:41:03
言語 C++17
(gcc 11.2.0 + boost 1.78.0)
結果
AC  
実行時間 63 ms / 2,000 ms
コード長 1,019 bytes
コンパイル時間 1,931 ms
使用メモリ 6,952 KB
最終ジャッジ日時 2023-01-11 06:17:53
合計ジャッジ時間 4,979 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
使用メモリ
testcase_00 AC 10 ms
4,904 KB
testcase_01 AC 13 ms
6,948 KB
testcase_02 AC 22 ms
4,904 KB
testcase_03 AC 29 ms
4,900 KB
testcase_04 AC 27 ms
4,900 KB
testcase_05 AC 33 ms
4,900 KB
testcase_06 AC 28 ms
4,904 KB
testcase_07 AC 25 ms
4,904 KB
testcase_08 AC 27 ms
6,948 KB
testcase_09 AC 26 ms
4,904 KB
testcase_10 AC 26 ms
4,904 KB
testcase_11 AC 35 ms
6,948 KB
testcase_12 AC 41 ms
6,952 KB
testcase_13 AC 32 ms
6,952 KB
testcase_14 AC 6 ms
4,900 KB
testcase_15 AC 32 ms
4,904 KB
testcase_16 AC 32 ms
6,948 KB
testcase_17 AC 33 ms
4,904 KB
testcase_18 AC 14 ms
4,904 KB
testcase_19 AC 31 ms
6,948 KB
testcase_20 AC 29 ms
4,900 KB
testcase_21 AC 33 ms
4,900 KB
testcase_22 AC 32 ms
4,900 KB
testcase_23 AC 59 ms
4,904 KB
testcase_24 AC 19 ms
4,904 KB
testcase_25 AC 33 ms
4,904 KB
testcase_26 AC 39 ms
4,908 KB
testcase_27 AC 13 ms
4,900 KB
testcase_28 AC 63 ms
4,908 KB
testcase_29 AC 62 ms
4,904 KB
testcase_30 AC 28 ms
4,904 KB
testcase_31 AC 29 ms
4,904 KB
testcase_32 AC 29 ms
4,904 KB
testcase_33 AC 29 ms
4,900 KB
testcase_34 AC 29 ms
6,948 KB
testcase_35 AC 28 ms
6,948 KB
testcase_36 AC 29 ms
6,948 KB
testcase_37 AC 29 ms
6,952 KB
testcase_38 AC 28 ms
4,904 KB
testcase_39 AC 29 ms
4,904 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

int64_t shift(int64_t x) { return x / 2 + (1ull << 15) * (x % 2); }

int main() {
    int64_t N;
    cin >> N;
    vector<int64_t> A(N);
    for (int64_t& a : A) {
        cin >> a;
    }

    const int64_t M = 16;
    const int64_t max_bit = (1ull << M);
    vector<bool> can_make(max_bit, false);
    can_make[0] = true;
    for (int64_t i = 0; i < N; i++) {
        vector<bool> new_can_make = can_make;
        for (int64_t k = 0; k < M; k++) {
            for (int64_t j = 0; j < max_bit; j++) {
                const int64_t nj = (j | A[i]);
                new_can_make[nj] = (new_can_make[nj] || can_make[j]);
            }

            A[i] = shift(A[i]);
        }

        can_make = new_can_make;
        if (can_make[max_bit - 1]) {
            cout << max_bit - 1 << endl;
            return 0;
        }
    }

    for (int64_t i = max_bit - 1; i >= 0; i--) {
        if (can_make[i]) {
            cout << i << endl;
            return 0;
        }
    }
}
0