QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#462137#5523. Graph Problem With Small $n$pavementTL 0ms3740kbC++17924b2024-07-03 14:45:442024-07-03 14:45:47

Judging History

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

  • [2024-07-03 14:45:47]
  • 评测
  • 测评结果:TL
  • 用时:0ms
  • 内存:3740kb
  • [2024-07-03 14:45:44]
  • 提交

answer

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

#define pb push_back
#define eb emplace_back
#define mp make_pair

using ii = pair<int, int>;

int n, dp[1 << 24][24];
char s[24][24];

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	cin >> n;
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n; j++) {
			cin >> s[i][j];
		}
	}
	for (int bm = (1 << n) - 1; bm >= 0; bm--) {
		for (int i = 0; i < n; i++) {
			if (!(bm & (1 << i))) {
				continue;
			}
			if (bm == (1 << n) - 1) {
				dp[bm][i] = 1 << i;
			} else {
				for (int j = 0; j < n; j++) {
					if ((bm & (1 << j)) || s[i][j] == '0') {
						continue;
					}
					dp[bm][i] |= dp[bm | (1 << j)][j];
				}
			}
		}
	}
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n; j++) {
			if (dp[1 << i][i] & (1 << j)) {
				cout << '1';
			} else {
				cout << '0';
			}
		}
		cout << '\n';
	}
	cout << '\n';
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

4
0110
1010
1101
0010

output:

0001
0001
0000
1100


result:

ok 4 lines

Test #2:

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

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: 3604kb

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: