結果

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

ソースコード

diff #

#define DEBUGGING  // Enables DEBUG macro.
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
using u64 = unsigned long long;
#define REP(i, n) for (int i = 0; (i64)(i) < (i64)(n); ++i)

#ifndef DEBUGGING
#define debug(...)
#define DEBUG(...)
#else
template <typename T>
void debug(T value) {
  std::cerr << value;
}
template <typename T, typename... Ts>
void debug(T value, Ts... args) {
  std::cerr << value << ", ";
  debug(args...);
}
#define DEBUG(...)                     \
  do {                                 \
    cerr << " (L" << __LINE__ << ") "; \
    cerr << #__VA_ARGS__ << ": ";      \
    debug(__VA_ARGS__);                \
    cerr << endl;                      \
  } while (0)
#endif

const i64 INF = 1LL << 40;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int N, K;
  cin >> N >> K;
  vector<i64> A(N);
  i64 mx = INF;
  for (auto& x : A) {
    cin >> x;
    mx = min(mx, x);
  }
  sort(A.rbegin(), A.rend());

  i64 ans = 0;
  auto solve = [&](auto rec, int i, i64 val) -> void {
    if (val < mx) {
      if (ans < val) ans = val;
      return;
    }
    if (i == N) {
      if (ans < val % mx) ans = val % mx;
      return;
    }

    rec(rec, i + 1, val);
    rec(rec, i + 1, val % A[i]);
  };
  solve(solve, 0, K);
  cout << ans << endl;
}
0