結果

問題 No.1538 引きこもりさんは引き算が得意。
ユーザー SSRSSSRS
提出日時 2021-06-06 18:45:08
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 53 ms / 2,000 ms
コード長 1,289 bytes
コンパイル時間 1,751 ms
コンパイル使用メモリ 173,728 KB
実行使用メモリ 9,004 KB
最終ジャッジ日時 2023-08-20 22:34:19
合計ジャッジ時間 4,123 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 1 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,380 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 1 ms
4,380 KB
testcase_13 AC 2 ms
4,380 KB
testcase_14 AC 1 ms
4,376 KB
testcase_15 AC 2 ms
4,376 KB
testcase_16 AC 1 ms
4,376 KB
testcase_17 AC 2 ms
4,380 KB
testcase_18 AC 1 ms
4,376 KB
testcase_19 AC 1 ms
4,380 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 1 ms
4,376 KB
testcase_24 AC 2 ms
4,376 KB
testcase_25 AC 1 ms
4,384 KB
testcase_26 AC 2 ms
4,376 KB
testcase_27 AC 1 ms
4,376 KB
testcase_28 AC 1 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 2 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 6 ms
4,380 KB
testcase_38 AC 6 ms
4,380 KB
testcase_39 AC 7 ms
4,376 KB
testcase_40 AC 6 ms
4,380 KB
testcase_41 AC 6 ms
4,376 KB
testcase_42 AC 6 ms
4,376 KB
testcase_43 AC 1 ms
4,376 KB
testcase_44 AC 6 ms
4,376 KB
testcase_45 AC 6 ms
4,376 KB
testcase_46 AC 3 ms
4,376 KB
testcase_47 AC 14 ms
5,196 KB
testcase_48 AC 53 ms
8,844 KB
testcase_49 AC 7 ms
4,376 KB
testcase_50 AC 1 ms
4,380 KB
testcase_51 AC 48 ms
8,848 KB
testcase_52 AC 49 ms
9,004 KB
testcase_53 AC 51 ms
8,944 KB
testcase_54 AC 51 ms
8,948 KB
testcase_55 AC 49 ms
9,004 KB
testcase_56 AC 53 ms
8,864 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
void dfs(vector<set<long long>> &st, vector<long long> &A, long long S = 0, int s = 0, int p = 0){
  int N = A.size();
  if (p == N){
    st[s].insert(S);
  } else {
    dfs(st, A, S, s, p + 1);
    dfs(st, A, S + A[p], s | 1, p + 1);
    dfs(st, A, S - A[p], s | 2, p + 1);
  }
}
int main(){
  int N;
  long long K;
  cin >> N >> K;
  vector<long long> A(N);
  for (int i = 0; i < N; i++){
    cin >> A[i];
  }
  bool ok = false;
  for (int i = 0; i < N; i++){
    if (A[i] == K){
      ok = true;
    }
  }
  if (ok){
    cout << "Yes" << endl;
  } else {
    int X = N / 2, Y = N - X;
    vector<long long> A1(X);
    for (int i = 0; i < X; i++){
      A1[i] = A[i];
    }
    vector<set<long long>> st1(4);
    dfs(st1, A1);
    vector<long long> A2(Y);
    for (int i = 0; i < Y; i++){
      A2[i] = A[X + i];
    }
    vector<set<long long>> st2(4);
    dfs(st2, A2);
    bool ok2 = false;
    for (int i = 0; i < 4; i++){
      for (int j = 0; j < 4; j++){
        if ((i | j) == 3){
          for (long long x : st1[i]){
            if (st2[j].count(K - x) == 1){
              ok2 = true;
            }
          }
        }
      }
    }
    if (ok2){
      cout << "Yes" << endl;
    } else {
      cout << "No" << endl;
    }
  }
}
0