結果

問題 No.943 取り調べ
ユーザー RubikunRubikun
提出日時 2019-12-05 22:07:47
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 68 ms / 1,206 ms
コード長 991 bytes
コンパイル時間 1,885 ms
コンパイル使用メモリ 170,332 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-24 17:00:18
合計ジャッジ時間 3,148 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 67 ms
4,380 KB
testcase_05 AC 60 ms
4,380 KB
testcase_06 AC 60 ms
4,380 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 68 ms
4,380 KB
testcase_09 AC 15 ms
4,380 KB
testcase_10 AC 15 ms
4,380 KB
testcase_11 AC 8 ms
4,384 KB
testcase_12 AC 2 ms
4,380 KB
testcase_13 AC 2 ms
4,384 KB
testcase_14 AC 2 ms
4,376 KB
testcase_15 AC 1 ms
4,376 KB
testcase_16 AC 2 ms
4,380 KB
testcase_17 AC 17 ms
4,376 KB
testcase_18 AC 2 ms
4,376 KB
testcase_19 AC 1 ms
4,380 KB
testcase_20 AC 2 ms
4,376 KB
testcase_21 AC 2 ms
4,380 KB
testcase_22 AC 17 ms
4,380 KB
testcase_23 AC 64 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define all(x) (x).begin(),(x).end()
const int mod=100000007,MAX=100005,INF=1<<30;

int main(){
    
    std::ifstream in("text.txt");
    std::cin.rdbuf(in.rdbuf());
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int N;cin>>N;
    vector<vector<int>> S(N,vector<int>(N));
    vector<int> dp((1<<N),INF);
    vector<int> A(N);
    
    for(int i=0;i<N;i++){
        for(int j=0;j<N;j++){
            cin>>S[i][j];
        }
    }
    
    for(int i=0;i<N;i++) cin>>A[i];
    
    dp[0]=0;
    
    for(int bit=0;bit<(1<<N);bit++){
        for(int i=0;i<N;i++){
            if(bit&(1<<i)) continue;
            bool ok=true;
            for(int j=0;j<N;j++){
                if(S[i][j]&&!(bit&(1<<j))) ok=false;
            }
            if(ok) dp[bit|(1<<i)]=min(dp[bit|(1<<i)],dp[bit]);
            else dp[bit|(1<<i)]=min(dp[bit|(1<<i)],dp[bit]+A[i]);
        }
    }
    
    cout<<dp[(1<<N)-1]<<endl;
    
}
0