結果

問題 No.1083 余りの余り
ユーザー HaarHaar
提出日時 2020-06-19 21:36:50
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,371 bytes
コンパイル時間 2,387 ms
コンパイル使用メモリ 209,340 KB
実行使用メモリ 93,228 KB
最終ジャッジ日時 2023-09-16 13:38:20
合計ジャッジ時間 5,630 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 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 WA -
testcase_05 AC 66 ms
23,600 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 2 ms
4,384 KB
testcase_11 WA -
testcase_12 AC 2 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,376 KB
testcase_17 AC 2 ms
4,380 KB
testcase_18 WA -
testcase_19 AC 64 ms
23,848 KB
testcase_20 AC 2 ms
4,380 KB
testcase_21 AC 7 ms
5,344 KB
testcase_22 AC 1 ms
4,376 KB
testcase_23 AC 331 ms
93,228 KB
testcase_24 AC 345 ms
93,060 KB
testcase_25 AC 333 ms
93,180 KB
testcase_26 AC 358 ms
93,164 KB
testcase_27 AC 1 ms
4,376 KB
testcase_28 WA -
testcase_29 AC 2 ms
4,380 KB
testcase_30 AC 1 ms
4,376 KB
testcase_31 AC 1 ms
4,376 KB
testcase_32 AC 2 ms
4,376 KB
testcase_33 AC 350 ms
93,068 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

/**
 * @title Fixed point combinator
 * @docs fix_point.md
 */
template <typename F>
struct FixPoint : F{
  explicit constexpr FixPoint(F &&f) noexcept : F(std::forward<F>(f)){}

  template <typename... Args>
  constexpr auto operator()(Args &&... args) const {
    return F::operator()(*this, std::forward<Args>(args)...);
  }
};

template <typename F>
inline constexpr auto make_fix_point(F &&f){
  return FixPoint<F>(std::forward<F>(f));
}

template <typename F>
inline constexpr auto make_fix_point(F &f){
  return FixPoint<F>(std::forward<F>(f));
}



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

    auto dp = std::vector(N+1, std::vector<int>(1 << N));
    auto check = std::vector(N+1, std::vector<bool>(1 << N));

    const int mask = (1 << N) - 1;
    
    auto f =
      make_fix_point(
        [&](auto &&f, int i, int s) -> int{
          if(check[i][s]) return dp[i][s];
          check[i][s] = true;

          if(i == 0 or s == 0) return dp[i][s] = K;

          for(int k = 0; k < N; ++k){
            if(s & (1 << k)){
              dp[i][s] = std::max(dp[i][s], f(i-1, s ^ (1 << k)) % A[k]);
            }
          }

          return dp[i][s];
        }
      );

    int ans = f(N, mask);
    std::cout << ans << "\n";
  }

  return 0;
}
0