結果

問題 No.1083 余りの余り
ユーザー Haar
提出日時 2020-06-19 21:36:50
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 1,371 bytes
コンパイル時間 2,361 ms
コンパイル使用メモリ 204,632 KB
最終ジャッジ日時 2025-01-11 05:53:41
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 27 WA * 4
権限があれば一括ダウンロードができます

ソースコード

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