結果

問題 No.1083 余りの余り
ユーザー tnakao0123
提出日時 2020-06-19 22:38:25
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 983 bytes
コンパイル時間 789 ms
コンパイル使用メモリ 93,756 KB
実行使用メモリ 7,808 KB
最終ジャッジ日時 2024-07-03 15:10:36
合計ジャッジ時間 2,523 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 27 WA * 4
権限があれば一括ダウンロードができます

ソースコード

diff #

/* -*- coding: utf-8 -*-
 *
 * 1083.cc:  No.1083 余りの余り - yukicoder
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

const int MAX_N = 20;
const int NBITS = 1 << MAX_N;

/* typedef */

/* global variables */

int as[MAX_N], dp[NBITS];

/* subroutines */

inline void setmax(int &a, int b) { if (a < b) a = b; }

/* main */

int main() {
  int n, k;
  scanf("%d%d", &n, &k);
  for (int i = 0; i < n; i++) scanf("%d", as + i);

  int nbits = 1 << n;
  dp[0] = k;

  for (int bits = 0; bits < nbits; bits++)
    for (int i = 0, bi = 1; i < n; i++, bi <<= 1)
      if (! (bits & bi))
	setmax(dp[bits | bi], dp[bits] % as[i]);

  printf("%d\n", dp[nbits - 1]);
  return 0;
}
0