結果

問題 No.1538 引きこもりさんは引き算が得意。
ユーザー 629e^-b629e^-b
提出日時 2021-06-14 22:51:36
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 3,118 bytes
コンパイル時間 4,408 ms
コンパイル使用メモリ 264,176 KB
実行使用メモリ 5,036 KB
最終ジャッジ日時 2023-08-26 09:11:47
合計ジャッジ時間 8,470 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 1 ms
4,380 KB
testcase_12 AC 1 ms
4,380 KB
testcase_13 AC 1 ms
4,376 KB
testcase_14 AC 2 ms
4,376 KB
testcase_15 AC 2 ms
4,376 KB
testcase_16 AC 1 ms
4,380 KB
testcase_17 AC 1 ms
4,380 KB
testcase_18 AC 1 ms
4,380 KB
testcase_19 AC 2 ms
4,376 KB
testcase_20 AC 2 ms
4,380 KB
testcase_21 AC 2 ms
4,380 KB
testcase_22 AC 2 ms
4,376 KB
testcase_23 AC 2 ms
4,384 KB
testcase_24 AC 2 ms
4,376 KB
testcase_25 AC 1 ms
4,376 KB
testcase_26 AC 2 ms
4,380 KB
testcase_27 AC 2 ms
4,380 KB
testcase_28 AC 2 ms
4,380 KB
testcase_29 AC 2 ms
4,376 KB
testcase_30 AC 1 ms
4,380 KB
testcase_31 AC 1 ms
4,380 KB
testcase_32 AC 1 ms
4,380 KB
testcase_33 AC 1 ms
4,380 KB
testcase_34 AC 2 ms
4,380 KB
testcase_35 AC 1 ms
4,376 KB
testcase_36 AC 2 ms
4,376 KB
testcase_37 AC 21 ms
4,836 KB
testcase_38 AC 22 ms
4,800 KB
testcase_39 AC 24 ms
4,748 KB
testcase_40 AC 19 ms
5,032 KB
testcase_41 AC 19 ms
4,804 KB
testcase_42 AC 21 ms
4,756 KB
testcase_43 AC 1 ms
4,376 KB
testcase_44 AC 19 ms
4,800 KB
testcase_45 AC 21 ms
5,036 KB
testcase_46 AC 19 ms
4,800 KB
testcase_47 AC 9 ms
4,380 KB
testcase_48 AC 27 ms
5,020 KB
testcase_49 AC 19 ms
4,872 KB
testcase_50 AC 1 ms
4,376 KB
testcase_51 AC 51 ms
4,904 KB
testcase_52 AC 25 ms
4,752 KB
testcase_53 AC 23 ms
4,864 KB
testcase_54 AC 51 ms
4,752 KB
testcase_55 AC 23 ms
4,732 KB
testcase_56 WA -
権限があれば一括ダウンロードができます

ソースコード

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<int> 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