結果

問題 No.1083 余りの余り
ユーザー chocono2230chocono2230
提出日時 2020-06-19 22:36:08
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 85 ms / 3,000 ms
コード長 1,182 bytes
コンパイル時間 1,687 ms
コンパイル使用メモリ 173,156 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-16 14:50:26
合計ジャッジ時間 3,458 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,384 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 2 ms
4,384 KB
testcase_05 AC 21 ms
4,380 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 1 ms
4,376 KB
testcase_11 AC 2 ms
4,384 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 1 ms
4,380 KB
testcase_14 AC 2 ms
4,380 KB
testcase_15 AC 1 ms
4,380 KB
testcase_16 AC 2 ms
4,380 KB
testcase_17 AC 2 ms
4,380 KB
testcase_18 AC 42 ms
4,376 KB
testcase_19 AC 21 ms
4,380 KB
testcase_20 AC 1 ms
4,376 KB
testcase_21 AC 4 ms
4,380 KB
testcase_22 AC 2 ms
4,380 KB
testcase_23 AC 84 ms
4,380 KB
testcase_24 AC 84 ms
4,380 KB
testcase_25 AC 85 ms
4,376 KB
testcase_26 AC 84 ms
4,376 KB
testcase_27 AC 2 ms
4,380 KB
testcase_28 AC 84 ms
4,376 KB
testcase_29 AC 1 ms
4,384 KB
testcase_30 AC 1 ms
4,380 KB
testcase_31 AC 2 ms
4,376 KB
testcase_32 AC 1 ms
4,380 KB
testcase_33 AC 82 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(ri,n) for(int ri = (int)(n-1); ri >= 0; ri--)
#define rep2(i,x,n) for(int i = (int)(x); i < (int)(n); i++)
#define repit(itr,x) for(auto itr = x.begin(); itr != x.end(); itr++)
#define rrepit(ritr,x) for(auto ritr = x.rbegin(); ritr != x.rend(); ritr++)
#define ALL(x) x.begin(), x.end()
using ll = long long;
using namespace std;

int dfs(vector<int> &a, int index, vector<bool> &chk, list<int> &list, int k){
  bool f = false;
  for(int i = index-1; i >= 0; i--){
    if(chk.at(i) == false){
      f = true;
      break;
    }
  }
  if(f == false){
    if(list.size() == 0) return -1;
    for(int i : list){
      k %= i;
    }
    return k;
  }
  int ret = -1;
  rep(i, index){
    list.push_back(a.at(i));
    chk.at(i) = true;
    int t = dfs(a, i, chk, list, k);
    ret = max(ret, t);
    chk.at(i) = false;
    list.pop_back();
  }
  return ret;
}

int main(){
  int n, k;
  cin >> n >> k;
  vector<int> a(n);
  rep(snip_i, n) cin >> a.at(snip_i);
  sort(ALL(a));
  vector<bool> chk(n, false);
  list<int> list;
  int ans = dfs(a, n, chk, list, k);
  cout << ans << endl;
  return 0;
}
0