提出 #47494911


ソースコード 拡げる

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using ld = long double;
using pll = pair<ll, ll>;
// and so on
ll mp[8][8];
int idx[8];
int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    ll N, M, K;
    cin >> N >> M >> K;
    for (int i = 0; i < N; i++) {
        for (int j = 0; j < N; j++) mp[i][j] = -1;
        idx[i] = i;
    }
    for (int i = 0; i < M; i++) {
        ll a, b, c;
        cin >> a >> b >> c;
        mp[a - 1][b - 1] = mp[b - 1][a - 1] = c;
    }
    ll ans = 1LL << 60;
    do {
        queue<ll> q[2];
        q[0].push(0);
        bool isok = true;
        for (int i = 1; i < N; i++) {
            queue<ll> &nxt = q[i % 2];
            queue<ll> &cnt = q[1 - i % 2];
            int e = idx[i];
            ll lst[8] = {
                0,
            };
            for (int j = 0; j < i; j++) {
                lst[j] = mp[idx[j]][e];
            }
            if (cnt.empty()) {
                isok = false;
                break;
            }
            while (!cnt.empty()) {
                ll x = cnt.front();
                cnt.pop();
                for (int j = 0; j < i; j++) {
                    if (lst[j] >= 0) nxt.push((x + lst[j]) % K);
                }
            }
        }
        queue<ll> fin = q[1 - N % 2];
        isok &= !fin.empty();
        if (isok) {
            while (!fin.empty()) {
                ll x = fin.front();
                fin.pop();
                ans = min(ans, x);
            }
        }
    } while (next_permutation(idx + 1, idx + N));
    cout << ans;
}

提出情報

提出日時
問題 E - Modulo MST
ユーザ jame0313
言語 C++ 20 (gcc 12.2)
得点 475
コード長 1667 Byte
結果 AC
実行時間 133 ms
メモリ 3676 KiB

ジャッジ結果

セット名 Sample All
得点 / 配点 0 / 0 475 / 475
結果
AC × 3
AC × 43
セット名 テストケース
Sample 00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt
All 00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt, 01_random_03.txt, 01_random_04.txt, 01_random_05.txt, 01_random_06.txt, 01_random_07.txt, 01_random_08.txt, 01_random_09.txt, 01_random_10.txt, 01_random_11.txt, 01_random_12.txt, 01_random_13.txt, 01_random_14.txt, 01_random_15.txt, 01_random_16.txt, 01_random_17.txt, 01_random_18.txt, 01_random_19.txt, 01_random_20.txt, 01_random_21.txt, 01_random_22.txt, 01_random_23.txt, 01_random_24.txt, 01_random_25.txt, 01_random_26.txt, 01_random_27.txt, 01_random_28.txt, 01_random_29.txt, 01_random_30.txt, 01_random_31.txt, 01_random_32.txt, 01_random_33.txt, 01_random_34.txt, 01_random_35.txt, 01_random_36.txt, 01_random_37.txt, 01_random_38.txt, 01_random_39.txt, 01_random_40.txt, 01_random_41.txt, 01_random_42.txt
ケース名 結果 実行時間 メモリ
00_sample_00.txt AC 1 ms 3552 KiB
00_sample_01.txt AC 1 ms 3452 KiB
00_sample_02.txt AC 133 ms 3600 KiB
01_random_03.txt AC 2 ms 3512 KiB
01_random_04.txt AC 1 ms 3500 KiB
01_random_05.txt AC 2 ms 3512 KiB
01_random_06.txt AC 70 ms 3676 KiB
01_random_07.txt AC 1 ms 3452 KiB
01_random_08.txt AC 1 ms 3492 KiB
01_random_09.txt AC 1 ms 3460 KiB
01_random_10.txt AC 1 ms 3416 KiB
01_random_11.txt AC 1 ms 3640 KiB
01_random_12.txt AC 1 ms 3512 KiB
01_random_13.txt AC 2 ms 3608 KiB
01_random_14.txt AC 7 ms 3508 KiB
01_random_15.txt AC 9 ms 3520 KiB
01_random_16.txt AC 26 ms 3404 KiB
01_random_17.txt AC 69 ms 3508 KiB
01_random_18.txt AC 55 ms 3552 KiB
01_random_19.txt AC 54 ms 3468 KiB
01_random_20.txt AC 3 ms 3488 KiB
01_random_21.txt AC 12 ms 3508 KiB
01_random_22.txt AC 2 ms 3504 KiB
01_random_23.txt AC 2 ms 3460 KiB
01_random_24.txt AC 1 ms 3452 KiB
01_random_25.txt AC 1 ms 3448 KiB
01_random_26.txt AC 1 ms 3456 KiB
01_random_27.txt AC 2 ms 3520 KiB
01_random_28.txt AC 1 ms 3448 KiB
01_random_29.txt AC 1 ms 3640 KiB
01_random_30.txt AC 68 ms 3568 KiB
01_random_31.txt AC 1 ms 3520 KiB
01_random_32.txt AC 1 ms 3504 KiB
01_random_33.txt AC 1 ms 3560 KiB
01_random_34.txt AC 1 ms 3492 KiB
01_random_35.txt AC 1 ms 3604 KiB
01_random_36.txt AC 1 ms 3476 KiB
01_random_37.txt AC 1 ms 3444 KiB
01_random_38.txt AC 1 ms 3476 KiB
01_random_39.txt AC 1 ms 3512 KiB
01_random_40.txt AC 33 ms 3648 KiB
01_random_41.txt AC 1 ms 3508 KiB
01_random_42.txt AC 1 ms 3604 KiB