結果
問題 | No.943 取り調べ |
ユーザー | ttttan2 |
提出日時 | 2019-12-06 20:55:53 |
言語 | C++11 (gcc 11.4.0) |
結果 |
AC
|
実行時間 | 261 ms / 1,206 ms |
コード長 | 2,656 bytes |
コンパイル時間 | 3,156 ms |
コンパイル使用メモリ | 152,900 KB |
実行使用メモリ | 4,384 KB |
最終ジャッジ日時 | 2023-08-25 11:42:25 |
合計ジャッジ時間 | 5,493 ms |
ジャッジサーバーID (参考情報) |
judge13 / judge12 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
4,380 KB |
testcase_01 | AC | 2 ms
4,380 KB |
testcase_02 | AC | 2 ms
4,380 KB |
testcase_03 | AC | 1 ms
4,380 KB |
testcase_04 | AC | 261 ms
4,376 KB |
testcase_05 | AC | 114 ms
4,380 KB |
testcase_06 | AC | 113 ms
4,376 KB |
testcase_07 | AC | 2 ms
4,384 KB |
testcase_08 | AC | 259 ms
4,380 KB |
testcase_09 | AC | 36 ms
4,380 KB |
testcase_10 | AC | 38 ms
4,380 KB |
testcase_11 | AC | 19 ms
4,380 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 | 1 ms
4,376 KB |
testcase_17 | AC | 44 ms
4,384 KB |
testcase_18 | AC | 1 ms
4,380 KB |
testcase_19 | AC | 1 ms
4,380 KB |
testcase_20 | AC | 1 ms
4,376 KB |
testcase_21 | AC | 1 ms
4,376 KB |
testcase_22 | AC | 50 ms
4,380 KB |
testcase_23 | AC | 97 ms
4,380 KB |
ソースコード
#include<bits/stdc++.h> //ios::sync_with_stdio(false);cin.tie(0);cout.tie(0); using namespace std; typedef long long ll; typedef unsigned long long ull; typedef pair<int,int> pii; typedef pair<pii,int> ppii; typedef pair<int,pii> pipi; typedef pair<ll,ll> pll; typedef pair<pll,ll> ppll; typedef pair<ll,pll> plpl; typedef tuple<ll,ll,ll> tl; ll mod=1000000007; ll mod2=998244353; ll mod3=1000003; ll mod4=998244853; ll inf=1000000000; double pi=2*acos(0); #define rep(i,m,n) for(ll i=m;i<n;i++) #define rrep(i,n,m) for(ll i=n;i>=m;i--) int dh[4]={1,-1,0,0}; int dw[4]={0,0,1,-1}; int ddh[8]={-1,-1,-1,0,0,1,1,1}; int ddw[8]={-1,0,1,-1,1,-1,0,1}; ll lmax(ll a,ll b){ if(a<b)return b; else return a; } ll lmin(ll a,ll b){ if(a<b)return a; else return b; } ll gcd(ll a,ll b){ if(a<b)swap(a,b); if(b==0)return a; if(a%b==0)return b; return gcd(b,a%b); } ll Pow(ll n,ll k){ ll ret=1; ll now=n; while(k>0){ if(k&1)ret*=now; now*=now; k/=2; } return ret; } ll beki(ll n,ll k,ll md){ ll ret=1; ll now=n; while(k>0){ if(k%2==1){ ret*=now; ret%=md; } now*=now; now%=md; k/=2; } return ret; } ll gyaku(ll n,ll md){ return beki(n,md-2,md); } int main(){ ios::sync_with_stdio(false);cin.tie(0); int n;cin>>n; vector<int> v[n]; ll su[n]; fill(su,su+n,0); rep(i,0,n){ rep(j,0,n){ int x;cin>>x; if(x==1){ v[j].push_back(i); su[i]++; } } } ll a[n];rep(i,0,n)cin>>a[i]; ll ans=inf; rep(i,0,1<<n){ ll sum=0; bool used[n]; fill(used,used+n,false); queue<ll> q; ll u=i; rep(j,0,n){ if(u%2==1){ q.push(j); used[j]=true; sum+=a[j]; } u/=2; } rep(j,0,n){ if(used[j]==false&&su[j]==0){ used[j]=true; q.push(j); } } ll cnt[n]; fill(cnt,cnt+n,0); while(q.size()>0){ ll now=q.front();q.pop(); rep(j,0,v[now].size()){ ll ne=v[now][j]; if(used[ne])continue; cnt[ne]++; if(cnt[ne]==su[ne]){ q.push(ne); used[ne]=true; } } } int r=0; rep(j,0,n){ if(used[j]==false){ r=1; break; } } if(r==0)ans=min(ans,sum); } cout<<ans<<endl; }