結果
| 問題 | No.943 取り調べ |
| コンテスト | |
| ユーザー |
ttttan2
|
| 提出日時 | 2019-12-06 20:55:53 |
| 言語 | C++11 (gcc 15.2.0 + boost 1.89.0) |
| 結果 |
AC
|
| 実行時間 | 182 ms / 1,206 ms |
| コード長 | 2,656 bytes |
| 記録 | |
| コンパイル時間 | 1,362 ms |
| コンパイル使用メモリ | 184,632 KB |
| 実行使用メモリ | 6,400 KB |
| 最終ジャッジ日時 | 2026-05-29 17:42:56 |
| 合計ジャッジ時間 | 3,244 ms |
|
ジャッジサーバーID (参考情報) |
judge1_1 / judge3_0 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 24 |
コンパイルメッセージ
In file included from /home/linuxbrew/.linuxbrew/Cellar/gcc/15.2.0_1/include/c++/15/algorithm:62,
from /home/linuxbrew/.linuxbrew/Cellar/gcc/15.2.0_1/include/c++/15/x86_64-pc-linux-gnu/bits/stdc++.h:53,
from main.cpp:1:
In function 'void std::__fill_a1(_ForwardIterator, _ForwardIterator, const _Tp&) [with _ForwardIterator = long long int*; _Tp = int]',
inlined from 'void std::__fill_a(_FIte, _FIte, const _Tp&) [with _FIte = long long int*; _Tp = int]' at /home/linuxbrew/.linuxbrew/Cellar/gcc/15.2.0_1/include/c++/15/bits/stl_algobase.h:979:21,
inlined from 'void std::fill(_ForwardIterator, _ForwardIterator, const _Tp&) [with _ForwardIterator = long long int*; _Tp = int]' at /home/linuxbrew/.linuxbrew/Cellar/gcc/15.2.0_1/include/c++/15/bits/stl_algobase.h:1011:20,
inlined from 'int main()' at main.cpp:72:9:
/home/linuxbrew/.linuxbrew/Cellar/gcc/15.2.0_1/include/c++/15/bits/stl_algobase.h:925:18: warning: 'void* __builtin_memset(void*, int, long unsigned int)' specified size between 18446744056529682432 and 18446744073709551608 exceeds maximum object size 9223372036854775807 [-Wstringop-overflow=]
925 | *__first = __val;
| ~~~~~~~~~^~~~~~~
ソースコード
#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;
}
ttttan2