結果

問題 No.943 取り調べ
ユーザー wunderkammer2wunderkammer2
提出日時 2020-01-28 14:07:31
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 199 ms / 1,206 ms
コード長 1,947 bytes
コンパイル時間 905 ms
コンパイル使用メモリ 100,692 KB
実行使用メモリ 4,352 KB
最終ジャッジ日時 2023-10-13 17:45:36
合計ジャッジ時間 3,599 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 1 ms
4,352 KB
testcase_03 AC 1 ms
4,348 KB
testcase_04 AC 48 ms
4,348 KB
testcase_05 AC 197 ms
4,352 KB
testcase_06 AC 199 ms
4,352 KB
testcase_07 AC 1 ms
4,348 KB
testcase_08 AC 49 ms
4,352 KB
testcase_09 AC 28 ms
4,348 KB
testcase_10 AC 25 ms
4,352 KB
testcase_11 AC 12 ms
4,352 KB
testcase_12 AC 1 ms
4,348 KB
testcase_13 AC 2 ms
4,348 KB
testcase_14 AC 1 ms
4,348 KB
testcase_15 AC 1 ms
4,352 KB
testcase_16 AC 2 ms
4,348 KB
testcase_17 AC 18 ms
4,348 KB
testcase_18 AC 1 ms
4,348 KB
testcase_19 AC 2 ms
4,348 KB
testcase_20 AC 2 ms
4,352 KB
testcase_21 AC 1 ms
4,348 KB
testcase_22 AC 15 ms
4,348 KB
testcase_23 AC 148 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<algorithm>
#include<cmath>
#include<cstdio>
#include<functional>
#include<iomanip>
#include<iostream>
#include<map>
#include<queue>
#include<set>
#include<string>
#include<utility>
#include<vector>

using namespace std;
typedef long long ll;
const ll mod = 1000000007;
#define rep(i,n) for(int i=0;i<n;i++)
#define repl(i,s,e) for(int i=s;i<e;i++)
#define reple(i,s,e) for(int i=s;i<=e;i++)
#define revrep(i,n) for(int i=n-1;i>=0;i--)
#define all(x) (x).begin(),(x).end()

int main()
{	
	int N;
	cin >> N;

	vector<vector<int>> X(N, vector<int>(N));
	rep(i, N)
		rep(j, N) cin >> X[i][j];

	vector<int> A(N);
	rep(i, N) cin >> A[i];

	
	//申し訳なさの合計の最小値
	//各Aが10^5、Nが18なので、10^7を超えない
	//※全員自白したと嘘をつけば、
	ll sum = 10000000;

	//bit全探索
	//N人のうち、うそをつく人のビットを1とする。
	rep(bit, (1 << N))
	{
		vector<bool> L(N, false);
		vector<bool> C(N, false);
		rep(i, N)
		{
			L[i] = (bit & (1 << i)) == (1 << i);
		}

		//自白ありフラグ
		bool flg = true;

		while (flg)
		{
			flg = false;

			//自白するかチェック
			rep(i, N)
			{
				if (C[i]) continue;

				bool flg2 = true;

				rep(j, N)
				{
					//頼りにしている人が自白もしていないし嘘もついていなかったら、チェック終了
					if (X[i][j] == 1 && !(L[j] || C[j]))
					{
						flg2 = false;
						break;
					}
				}

				//自白フラグON
				if (flg2)
				{
					flg = true;
					C[i] = true;
				}
			}
		} 
		

		//全員が自白したかチェック
		bool allC = true;
		rep(i, N)
		{
			if (!C[i])
			{
				allC = false;
				break;
			}
		}
			
		if (!allC) continue;

		//全員を自白できる組み合わせの場合、申し訳なさの計算
		//自白させた場合は加算しない
		ll tmp = 0;
		rep(i, N)
			if (L[i]) tmp += A[i];

		sum = min(sum, tmp);
	}


	cout << sum << endl;

    
	return 0;
}
0