結果

問題 No.1083 余りの余り
ユーザー yataro800yataro800
提出日時 2023-01-08 11:38:03
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,421 bytes
コンパイル時間 3,898 ms
コンパイル使用メモリ 229,184 KB
実行使用メモリ 208,252 KB
最終ジャッジ日時 2023-08-21 22:11:14
合計ジャッジ時間 19,609 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 420 ms
50,464 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 2 ms
4,384 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 1 ms
4,380 KB
testcase_14 AC 1 ms
4,380 KB
testcase_15 AC 2 ms
4,380 KB
testcase_16 AC 1 ms
4,388 KB
testcase_17 AC 2 ms
4,380 KB
testcase_18 AC 920 ms
97,340 KB
testcase_19 AC 422 ms
50,488 KB
testcase_20 AC 5 ms
4,380 KB
testcase_21 AC 39 ms
8,096 KB
testcase_22 AC 2 ms
4,376 KB
testcase_23 AC 2,032 ms
207,952 KB
testcase_24 AC 2,041 ms
207,944 KB
testcase_25 AC 2,035 ms
208,128 KB
testcase_26 AC 2,028 ms
207,988 KB
testcase_27 AC 1 ms
4,380 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,380 KB
testcase_32 AC 2 ms
4,380 KB
testcase_33 AC 2,044 ms
208,012 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#include <math.h>

#include <algorithm>
#include <array>
#include <atcoder/all>
#include <bitset>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <sstream>
#include <vector>

using namespace std;
using namespace atcoder;

using Graph = vector<vector<int>>;

using ll = long long;
typedef pair<ll, ll> P_ll;
typedef pair<int, int> P;

const ll INF_ll = 1e17;
const int INF = 1e8;
template <class T>
bool chmax(T& a, const T& b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
bool chmin(T& a, const T& b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
template <typename T>
using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;

int main() {
  ll N, K;
  cin >> N >> K;
  vector<ll> A(N);
  for (int i = 0; i < N; i++) {
    cin >> A[i];
  }
  vector<vector<ll>> dp(1 << N, vector<ll>(N, 0));
  for (int i = 0; i < N; i++) {
    dp[1 << i][i] = K % A[i];
  }
  for (int i = 0; i < 1 << N; i++) {
    for (int j = 0; j < N; j++) {
      if (((i >> j) & 1) == 0) {
        continue;
      }
      for (int k = 0; k < N; k++) {
        if (((i >> k) & 1) == 1) {
          continue;
        }
        int ni = i | (1 << k);
        chmax(dp[ni][k], dp[i][j] % A[k]);
      }
    }
  }
  ll ans = 0;
  for (int i = 0; i < N; i++) {
    chmax(ans, dp[(1 << N) - 1][i]);
  }
  cout << ans << endl;

  return 0;
}
0