結果

問題 No.1538 引きこもりさんは引き算が得意。
ユーザー 629e^-b629e^-b
提出日時 2021-06-14 22:52:57
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 50 ms / 2,000 ms
コード長 3,117 bytes
コンパイル時間 4,424 ms
コンパイル使用メモリ 263,884 KB
実行使用メモリ 6,224 KB
最終ジャッジ日時 2023-08-26 09:13:05
合計ジャッジ時間 6,805 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 1 ms
4,380 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 2 ms
4,376 KB
testcase_14 AC 2 ms
4,380 KB
testcase_15 AC 1 ms
4,384 KB
testcase_16 AC 1 ms
4,376 KB
testcase_17 AC 2 ms
4,380 KB
testcase_18 AC 1 ms
4,380 KB
testcase_19 AC 1 ms
4,380 KB
testcase_20 AC 2 ms
4,376 KB
testcase_21 AC 1 ms
4,380 KB
testcase_22 AC 1 ms
4,380 KB
testcase_23 AC 1 ms
4,376 KB
testcase_24 AC 1 ms
4,380 KB
testcase_25 AC 2 ms
4,376 KB
testcase_26 AC 1 ms
4,380 KB
testcase_27 AC 2 ms
4,376 KB
testcase_28 AC 2 ms
4,380 KB
testcase_29 AC 2 ms
4,380 KB
testcase_30 AC 2 ms
4,380 KB
testcase_31 AC 2 ms
4,376 KB
testcase_32 AC 1 ms
4,380 KB
testcase_33 AC 2 ms
4,380 KB
testcase_34 AC 1 ms
4,376 KB
testcase_35 AC 1 ms
4,376 KB
testcase_36 AC 1 ms
4,380 KB
testcase_37 AC 23 ms
6,064 KB
testcase_38 AC 21 ms
6,000 KB
testcase_39 AC 24 ms
6,132 KB
testcase_40 AC 19 ms
6,224 KB
testcase_41 AC 19 ms
6,124 KB
testcase_42 AC 21 ms
6,056 KB
testcase_43 AC 2 ms
4,376 KB
testcase_44 AC 19 ms
6,056 KB
testcase_45 AC 21 ms
5,972 KB
testcase_46 AC 19 ms
5,960 KB
testcase_47 AC 8 ms
4,600 KB
testcase_48 AC 26 ms
6,104 KB
testcase_49 AC 19 ms
6,112 KB
testcase_50 AC 2 ms
4,380 KB
testcase_51 AC 45 ms
6,000 KB
testcase_52 AC 25 ms
6,128 KB
testcase_53 AC 24 ms
6,132 KB
testcase_54 AC 50 ms
6,048 KB
testcase_55 AC 22 ms
6,128 KB
testcase_56 AC 47 ms
6,112 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using namespace atcoder;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using pii = pair<int, int>;
using pdd = pair<double, double>;
using pll = pair<ll, ll>;
using pli = pair<ll, int>;
using pil = pair<int, ll>;
template <typename T>
using Graph = vector<vector<T>>;
const int MOD = 1e9 + 7;
const ld PI = acos(-1);

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);

    int N, K;
    cin >> N >> K;
    vector<int> A(N);
    for (int i = 0; i < N; ++i) {
        cin >> A[i];
    }

    for (int i = 0; i < N; ++i) {
        if (A[i] == K) {
            cout << "Yes" << endl;
            return 0;
        }
    }

    vector<ll> v11, v12, v13, v21, v22, v23;
    int N1 = N / 2, N2 = N - N1;
    for (int i = 0; i < (1 << N1); ++i) {
        for (int j = i;; j = (j - 1) & i) {
            int a = i & j;
            int b = i ^ j;
            ll tmp = 0;
            for (int k = 0; k < N1; ++k) {
                if (!((i >> k) & 1))
                    continue;
                tmp += ((a >> k) & 1 ? A[k] : -A[k]);
            }
            v11.emplace_back(tmp);
            if (__builtin_popcount(a) != 0) {
                v13.emplace_back(tmp);
                if (__builtin_popcount(b) != 0)
                    v12.emplace_back(tmp);
            }
            if (j == 0)
                break;
        }
    }

    for (int i = 0; i < (1 << N2); ++i) {
        for (int j = i;; j = (j - 1) & i) {
            int a = i & j;
            int b = i ^ j;
            ll tmp = 0;
            for (int k = 0; k < N2; ++k) {
                if (!((i >> k) & 1))
                    continue;
                tmp += ((a >> k) & 1 ? A[k + N1] : -A[k + N1]);
            }
            v21.emplace_back(tmp);
            if (__builtin_popcount(b) != 0) {
                v23.emplace_back(tmp);
                if (__builtin_popcount(a) != 0)
                    v22.emplace_back(tmp);
            }
            if (j == 0)
                break;
        }
    }

    sort(v12.begin(), v12.end());
    sort(v22.begin(), v22.end());
    sort(v23.begin(), v23.end());
    for (auto i : v11) {
        auto itr = lower_bound(v22.begin(), v22.end(), K - i);
        if (itr != v22.end() && *itr == K - i) {
            cout << "Yes" << endl;
            return 0;
        }
    }
    for (auto i : v21) {
        auto itr = lower_bound(v12.begin(), v12.end(), K - i);
        if (itr != v12.end() && *itr == K - i) {
            cout << "Yes" << endl;
            return 0;
        }
    }
    for (auto i : v13) {
        {
            auto itr = lower_bound(v23.begin(), v23.end(), K - i);
            if (itr != v23.end() && *itr == K - i) {
                cout << "Yes" << endl;
                return 0;
            }
        }
        {
            auto itr = lower_bound(v23.begin(), v23.end(), -K - i);
            if (itr != v23.end() && *itr == K - i) {
                cout << "Yes" << endl;
                return 0;
            }
        }
    }
    cout << "No" << endl;

    return 0;
}
0