結果

問題 No.1083 余りの余り
ユーザー RenFukatsu
提出日時 2020-06-19 22:11:11
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 3 ms / 3,000 ms
コード長 1,281 bytes
コンパイル時間 2,477 ms
コンパイル使用メモリ 200,148 KB
最終ジャッジ日時 2025-01-11 06:30:29
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 31
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using ll = long long;

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

void dfs(int K, vector<int> &A, vector<bool> &is_used, int &ans)
{
    if(K < A[0])
    {
        chmax(ans, K);
        return;
    }
    for(int i=0; i<is_used.size(); i++)
    {
        if(is_used[i] || K < A[i]) continue;
        is_used[i] = true;
        dfs(K%A[i], A, is_used, ans);
        is_used[i] = false;
    }
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int N, K;
    cin >> N >> K;
    vector<int> A(N);
    for(int i=0; i<N; i++) cin >> A.at(i);
    // int N = 20;
    // int K = 1000000000;
    // vector<int> A(N);
    // std::mt19937 mt{ std::random_device{}() };

    // auto randint = [&](int lower, int upper)
    // {
    //     std::uniform_int_distribution<int> dist(lower, upper);
    //     return dist(mt);
    // };

    // for(int i=0; i<N; i++)
    // {
    //     A[i] = randint(1, 1000000000);
    // }

    sort(A.begin(), A.end());
    A.erase(unique(A.begin(), A.end()), A.end());

    vector<bool> is_used(A.size(), false);
    int ans = 0;
    dfs(K, A, is_used, ans);
    cout << ans << endl;
    


    return 0;
}
0