QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#462144#5523. Graph Problem With Small $n$pavementML 1639ms5628kbC++171.0kb2024-07-03 14:50:562024-07-03 14:50:57

Judging History

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

  • [2024-07-03 14:50:57]
  • 评测
  • 测评结果:ML
  • 用时:1639ms
  • 内存:5628kb
  • [2024-07-03 14:50:56]
  • 提交

answer

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

#pragma GCC optimize("O3")

#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 ls(int x) {
	return x & -x;
}

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 i = 0; i < n; i++) {
		dp[(1 << n) - 1][i] = 1 << i;
	}
	for (int bm = (1 << n) - 2; bm >= 0; bm--) {
		for (int tmp = bm; tmp; tmp -= ls(tmp)) {
			int i = 31 - __builtin_clz(ls(tmp));
			for (int tmp2 = ((1 << n) - 1) ^ bm; tmp2; tmp2 -= ls(tmp2)) {
				int j = 31 - __builtin_clz(ls(tmp2));
				if (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: 1ms
memory: 3660kb

input:

4
0110
1010
1101
0010

output:

0001
0001
0000
1100


result:

ok 4 lines

Test #2:

score: 0
Accepted
time: 1ms
memory: 3544kb

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: 1ms
memory: 3480kb

input:

4
0111
1011
1101
1110

output:

0111
1011
1101
1110


result:

ok 4 lines

Test #4:

score: 0
Accepted
time: 1639ms
memory: 5628kb

input:

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

output:

00000000000000000000000
00000000000000000000000
00000000000000000000000
00000000000000000000000
00000000000000000000000
00000000000000000000000
00000000000000000000000
00000000000000000000000
00000000000000000000000
00000000000000000000000
00000000000000000000000
00000000000000000000000
000000000000...

result:

ok 23 lines

Test #5:

score: -100
Memory Limit Exceeded

input:

23
00010100000000000101000
00000000010000000001000
00000000000001000000001
10000000000000000010000
00000000000000000000000
10000000000000000000000
00000001000000000000000
00000010000000000010000
00000000000001000000000
01000000000000000000000
00000000000000000000000
00000000000000000000000
000000000...

output:

00000000000000000000000
00000000000000000000000
00000000000000000000000
00000000000000000000000
00000000000000000000000
00000000000000000000000
00000000000000000000000
00000000000000000000000
00000000000000000000000
00000000000000000000000
00000000000000000000000
00000000000000000000000
000000000000...

result: