結果

問題 No.943 取り調べ
ユーザー hiro71687khiro71687k
提出日時 2023-04-12 17:02:08
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 152 ms / 1,206 ms
コード長 1,646 bytes
コンパイル時間 4,880 ms
コンパイル使用メモリ 256,152 KB
実行使用メモリ 50,432 KB
最終ジャッジ日時 2024-04-17 04:57:17
合計ジャッジ時間 5,968 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 1 ms
5,376 KB
testcase_03 AC 1 ms
5,376 KB
testcase_04 AC 133 ms
50,432 KB
testcase_05 AC 148 ms
50,304 KB
testcase_06 AC 152 ms
50,304 KB
testcase_07 AC 2 ms
5,376 KB
testcase_08 AC 129 ms
50,304 KB
testcase_09 AC 31 ms
13,952 KB
testcase_10 AC 30 ms
13,952 KB
testcase_11 AC 16 ms
8,192 KB
testcase_12 AC 2 ms
5,376 KB
testcase_13 AC 2 ms
5,376 KB
testcase_14 AC 2 ms
5,376 KB
testcase_15 AC 2 ms
5,376 KB
testcase_16 AC 1 ms
5,376 KB
testcase_17 AC 32 ms
14,080 KB
testcase_18 AC 2 ms
5,376 KB
testcase_19 AC 2 ms
5,376 KB
testcase_20 AC 2 ms
5,376 KB
testcase_21 AC 2 ms
5,376 KB
testcase_22 AC 32 ms
14,080 KB
testcase_23 AC 152 ms
50,304 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using namespace atcoder;
using ll=long long;
using ld=long double;
ld pie=3.141592653589793;
ll inf=1444999999999999;
ll mod=998244353;
int main(){
    ll n;
    cin >> n;
    vector<vector<ll>>x(n,vector<ll>(n));
    for (ll i = 0; i < n; i++)
    {
        for (ll j = 0; j < n; j++)
        {
            cin >> x[i][j];
        }
    }
    vector<ll>a(n);
    for (ll i = 0; i < n; i++)
    {
        cin >> a[i];
    }
    vector<ll>two(30,1);
    for (ll i = 1; i < 30; i++)
    {
        two[i]=two[i-1]*2;
    }
    vector<vector<ll>>dp(two[n],vector<ll>(n,inf));
    for (ll i = 0; i < n; i++)
    {
        dp[0][i]=0;
    }
    for (ll i = 1; i < two[n]; i++)
    {
        for (ll j = 0; j < n; j++)
        {
            if (i&two[j])
            {
                bool ok=true;
                for (ll k = 0; k < n; k++)
                {
                    if (x[j][k]&&!(i&two[k]))
                    {
                        ok=false;
                        break;
                    }
                }
                if (ok)
                {
                    for (ll k = 0; k < n; k++)
                    {
                        dp[i][j]=min(dp[i][j],dp[i-two[j]][k]);
                    }
                }else{
                    for (ll k = 0; k < n; k++)
                    {
                        dp[i][j]=min(dp[i][j],dp[i-two[j]][k]+a[j]);
                    }
                }
            }
        }
    }
    ll ans=inf;
    for (ll i = 0; i < n; i++)
    {
        ans=min(ans,dp[two[n]-1][i]);
    }
    cout << ans << endl;
}
0