QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#84537#5523. Graph Problem With Small $n$lnyxTL 2ms3532kbC++141.8kb2023-03-06 15:45:212023-03-06 15:45:54

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-03-06 15:45:54]
  • 评测
  • 测评结果:TL
  • 用时:2ms
  • 内存:3532kb
  • [2023-03-06 15:45:21]
  • 提交

answer

#include <cstdio>
#include <iostream>

namespace IO {
	template<typename T> inline void rd(T& x) {
		x = 0; bool f = 0; char s = getchar();
		while (s < '0' || s > '9') f |= s == '-', s = getchar();
		while ('0' <= s && s <= '9') x = x * 10 + (s - '0'), s = getchar();
		x = f ? -x : x;
	}
	template<typename T, typename ...Args> inline void rd(T& x, Args& ...args) { rd(x), rd(args...); } 
	template<typename T> inline void wt(T x, char s) {
		int stk[114], top = 0;
		if (x < 0) putchar('-'), x = -x;
		do stk[ ++ top] = x % 10, x /= 10; while (x);
		while (top) putchar(stk[top -- ] + '0');
		putchar(s);
	}
}
using namespace IO;
using namespace std;

const int N = 27;
char s[N];
int g[N];
int n, all;
int f[(1 << 24) + 7];
int ans[N];

inline int dp(int s) {
	if (f[s]) return f[s];
	for (int i = 1; i <= n; i ++ ) {
		if (!((s >> (i - 1)) & 1)) continue;
// 		if (s == 7) cerr << i << " " << dp(s ^ (1 << (i - 1))) << " " << g[i] << endl;
		f[s] |= (!!(dp(s ^ (1 << (i - 1))) & g[i])) << (i - 1);
	}
	return f[s];
}

int main() {
	#ifndef ONLINE_JUDGE 
	freopen("in.in", "r", stdin);
	freopen("out.out", "w", stdout);
	#endif
	rd(n), all = (1 << n) - 1;
	for (int i = 1; i <= n; i ++ ) {
		scanf("%s", s + 1);
		for (int j = 1; j <= n; j ++ ) {
			g[i] += (s[j] - '0') << (j - 1);
		}
// 		cerr << g[i] << endl;
	}
	f[1] = 1;
	dp(all);
// 	cerr << f[3] << " " << f[5] << " " << f[7] << endl;
	for (int i = 1; i <= n; i ++ ) {
		for (int s = 0; s <= all; s ++ ) {
			if ((f[s] >> (i - 1)) & 1) ans[i] |= f[all ^ s ^ 1];// , cerr << (all ^ s) << endl;
		}
	}
	for (int i = 1; i <= n; i ++ ) {
// 		cerr << ans[i] << endl;
		for (int j = 1; j <= n; j ++ ) {
			putchar(((ans[i] >> (j - 1)) & 1) + '0');
		}
		putchar('\n');
	}
	return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 2ms
memory: 3356kb

input:

4
0110
1010
1101
0010

output:

0001
0001
0000
1100

result:

ok 4 lines

Test #2:

score: 0
Accepted
time: 2ms
memory: 3384kb

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: 2ms
memory: 3532kb

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: