結果

問題 No.2071 Shift and OR
ユーザー tokumini_sstokumini_ss
提出日時 2022-09-16 21:41:03
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 67 ms / 2,000 ms
コード長 1,019 bytes
コンパイル時間 3,900 ms
コンパイル使用メモリ 205,188 KB
実行使用メモリ 4,860 KB
最終ジャッジ日時 2023-08-23 14:40:32
合計ジャッジ時間 5,131 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 11 ms
4,376 KB
testcase_01 AC 15 ms
4,376 KB
testcase_02 AC 24 ms
4,376 KB
testcase_03 AC 34 ms
4,376 KB
testcase_04 AC 31 ms
4,380 KB
testcase_05 AC 37 ms
4,380 KB
testcase_06 AC 31 ms
4,380 KB
testcase_07 AC 26 ms
4,380 KB
testcase_08 AC 30 ms
4,376 KB
testcase_09 AC 28 ms
4,376 KB
testcase_10 AC 29 ms
4,380 KB
testcase_11 AC 40 ms
4,376 KB
testcase_12 AC 47 ms
4,376 KB
testcase_13 AC 36 ms
4,376 KB
testcase_14 AC 6 ms
4,376 KB
testcase_15 AC 37 ms
4,376 KB
testcase_16 AC 37 ms
4,380 KB
testcase_17 AC 38 ms
4,380 KB
testcase_18 AC 15 ms
4,376 KB
testcase_19 AC 36 ms
4,380 KB
testcase_20 AC 34 ms
4,380 KB
testcase_21 AC 38 ms
4,376 KB
testcase_22 AC 37 ms
4,380 KB
testcase_23 AC 62 ms
4,860 KB
testcase_24 AC 20 ms
4,380 KB
testcase_25 AC 35 ms
4,380 KB
testcase_26 AC 41 ms
4,380 KB
testcase_27 AC 15 ms
4,376 KB
testcase_28 AC 67 ms
4,848 KB
testcase_29 AC 66 ms
4,688 KB
testcase_30 AC 32 ms
4,376 KB
testcase_31 AC 32 ms
4,380 KB
testcase_32 AC 32 ms
4,376 KB
testcase_33 AC 32 ms
4,380 KB
testcase_34 AC 32 ms
4,380 KB
testcase_35 AC 32 ms
4,376 KB
testcase_36 AC 32 ms
4,376 KB
testcase_37 AC 32 ms
4,376 KB
testcase_38 AC 32 ms
4,376 KB
testcase_39 AC 33 ms
4,376 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