QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#462164#5523. Graph Problem With Small $n$pavementML 176ms3660kbC++171.2kb2024-07-03 15:06:442024-07-03 15:06:44

Judging History

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

  • [2024-07-03 15:06:44]
  • 评测
  • 测评结果:ML
  • 用时:176ms
  • 内存:3660kb
  • [2024-07-03 15:06:44]
  • 提交

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, s[24], dp[1 << 24][24];
char ch;

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 >> ch;
			if (ch == '1') {
				s[i] |= (1 << j);
			}
		}
	}
	for (int i = 0; i < n; i++) {
		dp[(1 << n) - 1][i] = 1 << i;
	}
	for (int len = n - 1; len >= 1; len--) {
		int bm = (1 << len) - 1;
		int limit = (1 << n);
		while (bm < limit) {
			for (int tmp = bm; tmp; tmp -= ls(tmp)) {
				int i = 31 - __builtin_clz(ls(tmp));
				for (int tmp2 = (((1 << n) - 1) ^ bm) & s[i]; tmp2; tmp2 -= ls(tmp2)) {
					int j = 31 - __builtin_clz(ls(tmp2));
					dp[bm][i] |= dp[bm | ls(tmp2)][j];
				}
			}
			// Gosper's hack:
			int c = ls(bm);
			int r = bm + c;
			bm = (((r ^ bm) >> 2) / c) | r;
		}
	}
	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: 3608kb

input:

4
0110
1010
1101
0010

output:

0001
0001
0000
1100


result:

ok 4 lines

Test #2:

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

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

input:

4
0111
1011
1101
1110

output:

0111
1011
1101
1110


result:

ok 4 lines

Test #4:

score: 0
Accepted
time: 176ms
memory: 3468kb

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: