結果

問題 No.1538 引きこもりさんは引き算が得意。
ユーザー rogi52rogi52
提出日時 2022-10-22 12:50:22
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 61 ms / 2,000 ms
コード長 1,606 bytes
コンパイル時間 2,247 ms
コンパイル使用メモリ 210,760 KB
実行使用メモリ 7,128 KB
最終ジャッジ日時 2023-09-14 07:50:16
合計ジャッジ時間 5,298 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 1 ms
4,380 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 2 ms
4,376 KB
testcase_14 AC 2 ms
4,376 KB
testcase_15 AC 1 ms
4,380 KB
testcase_16 AC 2 ms
4,380 KB
testcase_17 AC 2 ms
4,376 KB
testcase_18 AC 2 ms
4,376 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,376 KB
testcase_23 AC 1 ms
4,384 KB
testcase_24 AC 2 ms
4,376 KB
testcase_25 AC 2 ms
4,380 KB
testcase_26 AC 2 ms
4,380 KB
testcase_27 AC 1 ms
4,384 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 1 ms
4,376 KB
testcase_32 AC 2 ms
4,376 KB
testcase_33 AC 1 ms
4,376 KB
testcase_34 AC 1 ms
4,376 KB
testcase_35 AC 1 ms
4,380 KB
testcase_36 AC 1 ms
4,380 KB
testcase_37 AC 26 ms
4,376 KB
testcase_38 AC 26 ms
4,376 KB
testcase_39 AC 19 ms
4,376 KB
testcase_40 AC 15 ms
4,376 KB
testcase_41 AC 15 ms
4,376 KB
testcase_42 AC 25 ms
4,380 KB
testcase_43 AC 1 ms
4,376 KB
testcase_44 AC 10 ms
4,380 KB
testcase_45 AC 23 ms
4,380 KB
testcase_46 AC 14 ms
4,376 KB
testcase_47 AC 9 ms
4,612 KB
testcase_48 AC 57 ms
7,084 KB
testcase_49 AC 22 ms
4,380 KB
testcase_50 AC 1 ms
4,376 KB
testcase_51 AC 60 ms
7,064 KB
testcase_52 AC 53 ms
7,076 KB
testcase_53 AC 53 ms
7,128 KB
testcase_54 AC 61 ms
7,072 KB
testcase_55 AC 46 ms
7,080 KB
testcase_56 AC 59 ms
7,084 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
using ld = long double;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(0);
    
    ll N,K; cin >> N >> K;
    vector<ll> A(N);
    rep(i,N) cin >> A[i];
    rep(i,N) if(A[i] == K) { cout << "Yes" << endl; return 0; }

    int N0 = N / 2, N1 = N - N / 2;
    vector<ll> A0, A1;
    rep(i,N0) A0.push_back(A[i]);
    rep(i,N1) A1.push_back(A[i + N0]);

    set<tuple<ll,int,int>> st0;
    rep(S,1<<N0) for(int T = S; ; T = (T - 1) & S) {
        int P = 0, M = 0;
        ll SUM = 0;
        rep(i,N0) {
            if(S & (1 << i)) {
                if(T & (1 << i)) {
                    SUM += A0[i];
                    P |= 1;
                } else {
                    SUM -= A0[i];
                    M |= 1;
                }
            }
        }
        st0.insert({SUM, P, M});
        if(T == 0) break;
    }

    rep(S,1<<N1) for(int T = S; ; T = (T - 1) & S) {
        int P = 0, M = 0;
        ll SUM =0;
        rep(i,N1) {
            if(S & (1 << i)) {
                if(T & (1 << i)) {
                    SUM += A1[i];
                    P |= 1;
                } else {
                    SUM -= A1[i];
                    M |= 1;
                }
            }
        }
        for(int p = 1 - P; p <= 1; p++)
            for(int m = 1 - M; m <= 1; m++)
                if(st0.count({K - SUM, p, m})) {
                    cout << "Yes" << endl;
                    return 0;
                }
        if(T == 0) break;
    }

    cout << "No" << endl;
}
0