結果

問題 No.1083 余りの余り
ユーザー Asdf_QwertyZAsdf_QwertyZ
提出日時 2020-06-22 04:22:52
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 397 ms / 3,000 ms
コード長 1,624 bytes
コンパイル時間 740 ms
コンパイル使用メモリ 84,152 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-16 19:06:02
合計ジャッジ時間 4,831 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <cstdio>
#include <cstdlib>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#define repi(i,a,b) for(ll i=(a);i<(b);++i)
#define rep(i,a) repi(i,0,a)
#define repdi(i,a,b) for(ll i=(a)-1;i>=(b);--i)
#define repd(i,a) repdi(i,a,0)
#define itr(it,a) for( auto it = (a).begin(); it != (a).end(); ++it )
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()

using ll = long long;
using P = std::pair<ll, ll>;

constexpr ll INF = 1ll<<60;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

template<class S, class T>
std::ostream& operator<< ( std::ostream& out, const std::pair<S,T>& a )
{ std::cout << '(' << a.first << ", " << a.second << ')'; return out; }

template<class T>
std::ostream &operator<< ( std::ostream& out, const std::vector<T>& a )
{ std::cout << '['; rep( i, a.size() ){ std::cout << a[i]; if( i != a.size()-1 ) std::cout << ", "; } std::cout << ']'; return out; }

ll N, K;
ll A[30];

int main()
{
  std::cin >> N >> K;

  rep( i, N )
    std::cin >> A[i];

  std::sort( A, A+N );

  ll ans = 0;

  repi( bit, 1, 1<<N ) {
    std::vector<ll> vs;
    
    rep( j, N ) if( bit>>j&1 )
      vs.emplace_back( j );

    ll x = K;

    repd( j, vs.size() )
      x %= A[vs[j]];

    rep( j, vs[0] )
      x %= A[j];

    chmax( ans, x );
  }

  std::cout << ans << std::endl;

  return 0;
}
0