結果

問題 No.1083 余りの余り
ユーザー AnchorBluesAnchorBlues
提出日時 2023-03-08 17:54:35
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,581 bytes
コンパイル時間 2,359 ms
コンパイル使用メモリ 172,684 KB
実行使用メモリ 208,128 KB
最終ジャッジ日時 2023-10-18 05:59:39
合計ジャッジ時間 17,822 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 2 ms
4,348 KB
testcase_04 AC 3 ms
4,348 KB
testcase_05 AC 432 ms
50,340 KB
testcase_06 AC 2 ms
4,348 KB
testcase_07 AC 2 ms
4,348 KB
testcase_08 AC 2 ms
4,348 KB
testcase_09 AC 2 ms
4,348 KB
testcase_10 AC 2 ms
4,348 KB
testcase_11 AC 2 ms
4,348 KB
testcase_12 AC 2 ms
4,348 KB
testcase_13 AC 2 ms
4,348 KB
testcase_14 AC 2 ms
4,348 KB
testcase_15 AC 2 ms
4,348 KB
testcase_16 AC 2 ms
4,348 KB
testcase_17 AC 2 ms
4,348 KB
testcase_18 AC 947 ms
97,392 KB
testcase_19 AC 431 ms
50,340 KB
testcase_20 AC 5 ms
4,348 KB
testcase_21 AC 40 ms
8,236 KB
testcase_22 AC 2 ms
4,348 KB
testcase_23 AC 2,078 ms
208,128 KB
testcase_24 AC 2,087 ms
208,128 KB
testcase_25 AC 2,075 ms
208,128 KB
testcase_26 AC 2,083 ms
208,128 KB
testcase_27 AC 2 ms
4,348 KB
testcase_28 WA -
testcase_29 AC 2 ms
4,348 KB
testcase_30 AC 2 ms
4,348 KB
testcase_31 AC 2 ms
4,348 KB
testcase_32 AC 2 ms
4,348 KB
testcase_33 AC 2,088 ms
208,128 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;
using ll = long long;
template <typename T>
using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using Graph = vector<vector<int>>;

const ll INF = 1LL << 60;

template <class T>
void chmax(T& a, T b) {
    if (b > a) a = b;
}
template <class T>
void chmin(T& a, T b) {
    if (b < a) a = b;
}

template <typename T, typename S>
std::ostream& operator<<(std::ostream& os, const pair<T, S>& x) noexcept {
    return os << "(" << x.first << ", " << x.second << ")";
}

template <typename T>
void print_vector(vector<T> a) {
    cout << '[';
    for (int i = 0; i < a.size(); i++) {
        cout << a[i];
        if (i != a.size() - 1) {
            cout << ", ";
        }
    }
    cout << ']' << endl;
}

int main() {
    ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    ll N, K;
    cin >> N >> K;
    vector<ll> A(N);
    for (int i = 0; i < N; i++) {
        cin >> A[i];
    }
    ll M = 1 << N;
    vector<vector<ll>> dp(M, vector<ll>(N, -1));
    for (int i = 0; i < N; i++) {
        dp[1 << i][i] = K % A[i];
    }
    for (int bit = 0; bit < M; bit++) {
        for (int i = 0; i < N; i++) {
            if (!((bit >> i) & 1)) continue;
            for (int j = 0; j < N; j++) {
                if (((bit >> j) & 1)) continue;
                chmax(dp[bit | (1 << j)][j], dp[bit][i] % A[j]);
            }
        }
    }
    ll ret = 0;
    for (auto& v : dp[M - 1]) {
        chmax(ret, v);
    }
    std::cout << ret << "\n";
    return 0;
}
0