提出 #57884924


ソースコード 拡げる

#include <bits/stdc++.h>
#include <atcoder/all>

#define all(x) (x).begin(), (x).end()
#define fix(x) fixed << setprecision(x)
#define rep(i, start, end) for (auto i = (start); (i) < (end); (i)++)
#define rrep(i, start, end) for (auto i = (start); (i) >= (end); (i)--)

constexpr auto PI = 3.14159265358979;
constexpr auto INF = 1e+9;
constexpr auto INFL = 1LL << 60;

using namespace std;
using namespace atcoder;
using ll = long long;
using lld = long double;
// using mint = modint1000000007;
using mint = modint998244353;
using Pair_int = pair<int, int>;
using Pair_ll = pair<ll, ll>;
template <class T>
using Graph = vector<vector<T>>;

template <class T1, class T2>
inline auto div_floor(T1 a, T2 b)
{
    if (b < 0)
        a *= -1, b *= -1;
    if (a >= 0)
        return a / b;
    else
        return (a + 1) / b - 1;
}
template <class T1, class T2>
inline auto div_ceil(T1 a, T2 b)
{
    if (b < 0)
        a *= -1, b *= -1;
    if (a <= 0)
        return a / b;
    else
        return (a - 1) / b + 1;
}
ll pow(ll x, ll n)
{
    ll res = 1;
    while (n > 0)
    {
        if (n & 1)
            res *= x;
        x *= x;
        n >>= 1;
    }
    return res;
}
ll pow_mod(ll x, ll n, ll mod)
{
    ll res = 1;
    while (n > 0)
    {
        if (n & 1)
            res = res * x % mod;
        x = x * x % mod;
        n >>= 1;
    }
    return res;
}
ll gcd(ll x, ll y)
{
    if (x < y)
        swap(x, y);
    ll r;
    while (y > 0)
    {
        r = x % y;
        x = y;
        y = r;
    }
    return x;
}
ll lcm(ll x, ll y) { return ll(x / gcd(x, y)) * y; }
ll nCk(ll n, ll r)
{
    if (r < 0 || n < r)
        return 0;
    ll ans = 1;
    for (ll i = 1; i <= r; i++)
    {
        ans *= n--;
        ans /= i;
    }
    return ans;
}
int get_rand(int seed, int min, int max)
{
    static mt19937_64 mt64(seed);
    uniform_int_distribution<int> get_rand_int(min, max);
    return get_rand_int(mt64);
}
template <typename T>
inline bool chmax(T &a, T b) { return ((a < b) ? (a = b, true) : (false)); }
template <typename T>
inline bool chmin(T &a, T b) { return ((a > b) ? (a = b, true) : (false)); }
template <class T1, class T2>
inline auto mod(T1 x, T2 r) { return (x % r + r) % r; }

// ======================================== //

int main()
{
    int N;
    cin >> N;

    int M_G;
    cin >> M_G;
    vector<vector<bool>> G(N, vector<bool>(N, false));
    rep(i, 0, M_G)
    {
        int u, v;
        cin >> u >> v;
        u--, v--;
        G[u][v] = G[v][u] = true;
    }

    int M_H;
    cin >> M_H;
    vector<vector<bool>> H(N, vector<bool>(N, false));
    rep(i, 0, M_H)
    {
        int a, b;
        cin >> a >> b;
        a--, b--;
        H[a][b] = H[b][a] = true;
    }


    vector<vector<int>> A(N, vector<int>(N));
    rep(i, 0, N) rep(j, i + 1, N) cin >> A[i][j];

    vector<int> order(N);
    iota(all(order), 0);

    int ans = INF;
    
    do
    {
        int sum = 0;
        rep(i, 0, N) rep(j, i + 1, N)
        {
            if (G[order[i]][order[j]] != H[i][j])
            {
                sum += A[i][j];
            }
        }

        chmin(ans, sum);
    } while (next_permutation(all(order)));
    
    cout << ans << endl;
}

提出情報

提出日時
問題 C - Make Isomorphic
ユーザ Yuulis
言語 C++ 23 (gcc 12.2)
得点 300
コード長 3195 Byte
結果 AC
実行時間 10 ms
メモリ 3700 KiB

ジャッジ結果

セット名 Sample All
得点 / 配点 0 / 0 300 / 300
結果
AC × 5
AC × 56
セット名 テストケース
Sample 00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt, 00_sample_03.txt, 00_sample_04.txt
All 00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt, 00_sample_03.txt, 00_sample_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, 01_random_43.txt, 01_random_44.txt, 01_random_45.txt, 01_random_46.txt, 01_random_47.txt, 01_random_48.txt, 01_random_49.txt, 01_random_50.txt, 01_random_51.txt, 01_random_52.txt, 01_random_53.txt, 01_random_54.txt, 01_random_55.txt
ケース名 結果 実行時間 メモリ
00_sample_00.txt AC 10 ms 3552 KiB
00_sample_01.txt AC 1 ms 3544 KiB
00_sample_02.txt AC 1 ms 3488 KiB
00_sample_03.txt AC 1 ms 3488 KiB
00_sample_04.txt AC 8 ms 3496 KiB
01_random_05.txt AC 5 ms 3500 KiB
01_random_06.txt AC 6 ms 3544 KiB
01_random_07.txt AC 8 ms 3564 KiB
01_random_08.txt AC 8 ms 3532 KiB
01_random_09.txt AC 8 ms 3516 KiB
01_random_10.txt AC 8 ms 3496 KiB
01_random_11.txt AC 6 ms 3480 KiB
01_random_12.txt AC 8 ms 3548 KiB
01_random_13.txt AC 6 ms 3636 KiB
01_random_14.txt AC 6 ms 3644 KiB
01_random_15.txt AC 1 ms 3492 KiB
01_random_16.txt AC 1 ms 3500 KiB
01_random_17.txt AC 1 ms 3696 KiB
01_random_18.txt AC 1 ms 3636 KiB
01_random_19.txt AC 1 ms 3616 KiB
01_random_20.txt AC 4 ms 3500 KiB
01_random_21.txt AC 5 ms 3700 KiB
01_random_22.txt AC 4 ms 3508 KiB
01_random_23.txt AC 3 ms 3544 KiB
01_random_24.txt AC 5 ms 3552 KiB
01_random_25.txt AC 4 ms 3564 KiB
01_random_26.txt AC 4 ms 3548 KiB
01_random_27.txt AC 5 ms 3488 KiB
01_random_28.txt AC 5 ms 3640 KiB
01_random_29.txt AC 7 ms 3548 KiB
01_random_30.txt AC 3 ms 3496 KiB
01_random_31.txt AC 6 ms 3496 KiB
01_random_32.txt AC 8 ms 3696 KiB
01_random_33.txt AC 8 ms 3496 KiB
01_random_34.txt AC 3 ms 3564 KiB
01_random_35.txt AC 5 ms 3504 KiB
01_random_36.txt AC 4 ms 3540 KiB
01_random_37.txt AC 5 ms 3496 KiB
01_random_38.txt AC 3 ms 3500 KiB
01_random_39.txt AC 4 ms 3504 KiB
01_random_40.txt AC 5 ms 3492 KiB
01_random_41.txt AC 4 ms 3492 KiB
01_random_42.txt AC 3 ms 3508 KiB
01_random_43.txt AC 3 ms 3504 KiB
01_random_44.txt AC 8 ms 3504 KiB
01_random_45.txt AC 8 ms 3548 KiB
01_random_46.txt AC 7 ms 3548 KiB
01_random_47.txt AC 3 ms 3548 KiB
01_random_48.txt AC 4 ms 3496 KiB
01_random_49.txt AC 3 ms 3504 KiB
01_random_50.txt AC 8 ms 3508 KiB
01_random_51.txt AC 8 ms 3552 KiB
01_random_52.txt AC 8 ms 3696 KiB
01_random_53.txt AC 6 ms 3552 KiB
01_random_54.txt AC 7 ms 3500 KiB
01_random_55.txt AC 8 ms 3608 KiB