QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#282459#5523. Graph Problem With Small $n$duckierTL 0ms3600kbC++141.1kb2023-12-12 07:27:232023-12-12 07:27:24

Judging History

你现在查看的是最新测评结果

  • [2023-12-12 07:27:24]
  • 评测
  • 测评结果:TL
  • 用时:0ms
  • 内存:3600kb
  • [2023-12-12 07:27:23]
  • 提交

answer

#include <bits/stdc++.h>
#define int long long

using namespace std;

const int MAXN = 24;
int n, dp[1 << MAXN], adj[MAXN], ans[MAXN];
string s[MAXN];

signed main() {
	cin >> n;
	for (int i = 1; i <= n; i++) cin >> s[i];
	for (int i = 1; i <= n; i++) {
		for (int j = 0; j < n; j++) {
			if (s[i][j] == '1') adj[i] ^= 1LL << j;
		}
	}
	dp[1] = 1;
	for (int i = 2; i < 1 << n; i++) {
		vector<int> v;
		for (int j = 0; j < n; j++) {
			if ((1 << j) & i)v.push_back(j);
		}
		if (v[0] != 0)continue;
		for (int x : v) {
			if (dp[i ^ (1 << x)] & adj[x + 1]) {
				dp[i] |= 1 << x;
			}
		}
	}
	for (int c = 1; c <= n; c++) {
		for (int i = 1; i < 1 << n; i++) {
			vector<int> v;
			for (int j = 0; j < n; j++) {
				if ((1 << j) & i)v.push_back(j);
			}
			if (v[0] != 0)continue;
			if (!(dp[i] & (1 << (c - 1))))continue;
			int comp = (((1 << n) - 1) ^ i) + 1;
			ans[c] |= dp[comp];
		}
	}
	for (int i = 1; i <= n; i++) {
		for (int j = 0; j < n; j++) {
			if (ans[i] & (1 << j)) {
				cout << '1';
			}
			else {
				cout << '0';
			}
		}
		cout << '\n';
	}
}

詳細信息

Test #1:

score: 100
Accepted
time: 0ms
memory: 3596kb

input:

4
0110
1010
1101
0010

output:

0001
0001
0000
1100

result:

ok 4 lines

Test #2:

score: 0
Accepted
time: 0ms
memory: 3480kb

input:

6
010001
101000
010100
001010
000101
100010

output:

010001
101000
010100
001010
000101
100010

result:

ok 6 lines

Test #3:

score: 0
Accepted
time: 0ms
memory: 3600kb

input:

4
0111
1011
1101
1110

output:

0111
1011
1101
1110

result:

ok 4 lines

Test #4:

score: -100
Time Limit Exceeded

input:

23
00000000000000000000000
00000000000000000000000
00000000000000000000000
00000000000000000000000
00000000000000000000000
00000000000000000000000
00000000000000000000000
00000000000000000000000
00000000000000000000000
00000000000000000000000
00000000000000000000000
00000000000000000000000
000000000...

output:


result: