結果

問題 No.2911 位相の公理
ユーザー eve__fuyuki
提出日時 2024-10-07 01:50:46
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 1,158 ms / 2,000 ms
コード長 1,007 bytes
コンパイル時間 1,842 ms
コンパイル使用メモリ 199,136 KB
最終ジャッジ日時 2025-02-24 16:14:59
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 24
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

void fast_io() {
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
}

int main() {
	fast_io();
	int n, m;
	cin >> n >> m;
	vector<int> s;
	vector<bool> exist(1 << n, false);
	for (int i = 0; i < m; i++) {
		string a;
		cin >> a;
		int num = 0;
		for (int j = 0; j < n; j++) {
			if (a[j] == '1') {
				num += 1 << j;
			}
		}
		s.push_back(num);
		exist[num] = true;
	}
	vector<bool> dp(1 << n, false);
	dp[0] = true;
	for (int i = 0; i < m; i++) {
		for (int j = (1 << n) - 1; j >= 0; j--) {
			if (dp[j]) {
				dp[j | s[i]] = true;
			}
		}
	}
	if (!exist[(1 << n) - 1]) {
		cout << "No" << endl;
		return 0;
	}
	for (int i = 0; i < (1 << n); i++) {
		if (dp[i] && !exist[i]) {
			cout << "No" << endl;
			return 0;
		}
	}
	for (int i = 0; i < (1 << n); i++) {
		if (!exist[i]) {
			continue;
		}
		for (int j = i + 1; j < (1 << n); j++) {
			if (exist[j] && !exist[i & j]) {
				cout << "No" << endl;
				return 0;
			}
		}
	}
	cout << "Yes" << endl;
}
0