提出 #18345306


ソースコード 拡げる

#include <bits/stdc++.h>
using namespace std;
using ll = long long;

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

  ll N; cin >> N;
  ll T; cin >> T;
  vector<ll> A(N); for (ll i = 0; i < N; i++) cin >> A[i];

  set<ll> st1, st2;
  ll m1 = N / 2, m2 = N - m1;
  st1.insert(0);
  st2.insert(0);
  for (ll i = 0; i < (1 << m1); i++) {
    ll temp = 0;
    for (ll j = 0; j < m1; j++) {
      if ((i>>j) & 1) temp += A[j];
    }
    st1.insert(temp);
  }
  for (ll i = 0; i < (1 << m2); i++) {
    ll temp = 0;
    for (ll j = 0; j < m2; j++) {
      if ((i>>j) & 1) temp -= A[m1 + j];
    }
    st2.insert(temp);
  }

// for (auto itr = st1.begin(); itr != st1.end(); ++itr) {
//   cout << *itr << "\n";
// }
// for (auto itr = st2.begin(); itr != st2.end(); ++itr) {
//   cout << *itr << "\n";
// }

  ll ans = 0;
  for (auto itr = st1.begin(); itr != st1.end(); ++itr) {
    ll temp = *itr;
    if (temp > T) continue;
    auto itr2 = st2.lower_bound(temp - T);
    // auto itr2 = lower_bound(st2.begin(), st2.end(), T - temp);
    ll l = *itr2;
    if (temp - l <= T) {
      ans = max(ans, temp - l);
    }
  }

  cout << ans << '\n';
  return 0;
}

提出情報

提出日時
問題 F - Programming Contest
ユーザ nakaken88
言語 C++ (GCC 9.2.1)
得点 600
コード長 1216 Byte
結果 AC
実行時間 1263 ms
メモリ 101836 KiB

ジャッジ結果

セット名 Sample All
得点 / 配点 0 / 0 600 / 600
結果
AC × 4
AC × 35
セット名 テストケース
Sample sample_01.txt, sample_02.txt, sample_03.txt, sample_04.txt
All hand_01.txt, random_01.txt, random_02.txt, random_03.txt, random_04.txt, random_05.txt, random_06.txt, random_07.txt, random_08.txt, random_09.txt, random_10.txt, random_11.txt, random_12.txt, random_13.txt, random_14.txt, random_15.txt, random_16.txt, random_17.txt, random_18.txt, random_19.txt, random_20.txt, random_21.txt, random_22.txt, random_23.txt, random_24.txt, random_25.txt, random_26.txt, random_27.txt, random_28.txt, random_29.txt, random_30.txt, sample_01.txt, sample_02.txt, sample_03.txt, sample_04.txt
ケース名 結果 実行時間 メモリ
hand_01.txt AC 3 ms 3628 KiB
random_01.txt AC 2 ms 3492 KiB
random_02.txt AC 2 ms 3624 KiB
random_03.txt AC 2 ms 3468 KiB
random_04.txt AC 2 ms 3504 KiB
random_05.txt AC 2 ms 3564 KiB
random_06.txt AC 3 ms 3596 KiB
random_07.txt AC 3 ms 3472 KiB
random_08.txt AC 3 ms 3600 KiB
random_09.txt AC 2 ms 3596 KiB
random_10.txt AC 2 ms 3472 KiB
random_11.txt AC 2 ms 3640 KiB
random_12.txt AC 9 ms 3696 KiB
random_13.txt AC 155 ms 21864 KiB
random_14.txt AC 3 ms 3468 KiB
random_15.txt AC 2 ms 3556 KiB
random_16.txt AC 2 ms 3588 KiB
random_17.txt AC 2 ms 3544 KiB
random_18.txt AC 2 ms 3588 KiB
random_19.txt AC 22 ms 5772 KiB
random_20.txt AC 148 ms 21860 KiB
random_21.txt AC 8 ms 3928 KiB
random_22.txt AC 150 ms 21904 KiB
random_23.txt AC 1181 ms 101804 KiB
random_24.txt AC 1179 ms 101792 KiB
random_25.txt AC 1144 ms 101836 KiB
random_26.txt AC 1217 ms 101736 KiB
random_27.txt AC 1263 ms 101452 KiB
random_28.txt AC 133 ms 3536 KiB
random_29.txt AC 133 ms 3596 KiB
random_30.txt AC 133 ms 3484 KiB
sample_01.txt AC 2 ms 3496 KiB
sample_02.txt AC 2 ms 3548 KiB
sample_03.txt AC 2 ms 3472 KiB
sample_04.txt AC 2 ms 3544 KiB