結果

問題 No.943 取り調べ
ユーザー chocoruskchocorusk
提出日時 2019-12-05 22:12:29
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 556 ms / 1,206 ms
コード長 1,940 bytes
コンパイル時間 1,005 ms
コンパイル使用メモリ 114,264 KB
実行使用メモリ 24,060 KB
最終ジャッジ日時 2023-08-24 17:10:43
合計ジャッジ時間 5,553 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 9 ms
24,012 KB
testcase_01 AC 9 ms
23,820 KB
testcase_02 AC 8 ms
23,816 KB
testcase_03 AC 9 ms
23,820 KB
testcase_04 AC 521 ms
23,804 KB
testcase_05 AC 477 ms
23,912 KB
testcase_06 AC 477 ms
23,948 KB
testcase_07 AC 10 ms
23,804 KB
testcase_08 AC 521 ms
23,784 KB
testcase_09 AC 166 ms
23,876 KB
testcase_10 AC 169 ms
23,780 KB
testcase_11 AC 88 ms
23,876 KB
testcase_12 AC 9 ms
23,876 KB
testcase_13 AC 8 ms
23,780 KB
testcase_14 AC 9 ms
24,060 KB
testcase_15 AC 8 ms
23,824 KB
testcase_16 AC 9 ms
23,796 KB
testcase_17 AC 179 ms
23,828 KB
testcase_18 AC 10 ms
23,872 KB
testcase_19 AC 9 ms
23,820 KB
testcase_20 AC 9 ms
23,888 KB
testcase_21 AC 9 ms
23,800 KB
testcase_22 AC 174 ms
23,820 KB
testcase_23 AC 556 ms
23,796 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
#include <fstream>
#include <utility>
#include <functional>
#include <time.h>
#include <stack>
#include <array>
#define popcount __builtin_popcount
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> P;
int n;
bool used[400001];
int cmp[400001];
vector<int> g[400001], gr[400001];
vector<int> vs;
void init(){
    fill(used, used+n, 0);
    fill(cmp, cmp+n, 0);
    for(int i=0; i<n; i++){
        g[i].clear();
        gr[i].clear();
    }
    vs.clear();
}
void dfs(int x){
	used[x]=1;
	for(auto y:g[x]){
		if(!used[y]) dfs(y);
	}
	vs.push_back(x);
}
void rdfs(int v, int k){
	used[v]=1;
	cmp[v]=k;
	for(auto y:gr[v]){
		if(!used[y]) rdfs(y, k);
	}
}
int scc(){
	fill(used, used+n, 0);
	vs.clear();
	for(int i=0; i<n; i++){
		if(!used[i]) dfs(i);
	}
	fill(used, used+n, 0);
	int k=0;
	for(int i=vs.size()-1; i>=0; i--){
		if(!used[vs[i]]) rdfs(vs[i], k++);
	}
	return k;
}
int main()
{
    cin>>n;
    int x[20][20];
    for(int i=0; i<n; i++){
        for(int j=0; j<n; j++){
            cin>>x[i][j];
        }
    }
    int a[20];
    for(int i=0; i<n; i++) cin>>a[i];
    const int INF=1e9;
    int ans=INF;
    for(int i=0; i<(1<<n); i++){
        int s=0;
        for(int j=0; j<n; j++){
            if(i&(1<<j)) continue;
            s+=a[j];
        }
        init();
        for(int j=0; j<n; j++){
            for(int k=0; k<n; k++){
                if(i&(1<<k) && x[j][k]){
                    g[k].push_back(j);
                    gr[j].push_back(k);
                }
            }
        }
        int k=scc();
        if(k==n) ans=min(ans, s);
    }
    cout<<ans<<endl;
    return 0;
}
0