結果

問題 No.1083 余りの余り
ユーザー hipotaf
提出日時 2020-06-19 22:12:30
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 190 ms / 3,000 ms
コード長 1,174 bytes
コンパイル時間 767 ms
コンパイル使用メモリ 80,572 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-07-03 14:52:31
合計ジャッジ時間 2,920 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 31
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <bitset>

using namespace std;

using ll = long long;

#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)

#define input(...) __VA_ARGS__; in(__VA_ARGS__)

template<class T>
void print(vector<T> a) {
  cout << "[ ";
  REP(i, a.size()) cout << a[i] << " ";
  cout << "]" << endl;
}

void print() {
  std::cout << std::endl;
}

template <class Head, class... Tail>
void print(Head&& head, Tail&&... tail) {
  std::cout << head << " ";
  print(std::forward<Tail>(tail)...);
}

void in() { }

template <class Head, class... Tail>
void in(Head&& head, Tail&&... tail) {
  cin >> head;
  in(std::forward<Tail>(tail)...);
}

int main() {
  ll input(n, k);
  vector<ll> a(n);
  REP(i, n) cin >> a[i];
  sort(a.begin(), a.end());
  ll minv = a[0];
  ll maxv = 0;
  REP(i, 1 << n) {
    bitset<20> state(i);

    ll ans = k;
    REPD(j, 20) {
      if (state[j]) {
        ans %= a[j];
      }
    }
    maxv = max(maxv, ans % minv);
  }
  print(maxv);
}
0