QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#338226#5523. Graph Problem With Small $n$ERosIonRE 0ms0kbC++141.5kb2024-02-25 19:22:362024-02-25 19:22:36

Judging History

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

  • [2024-02-25 19:22:36]
  • 评测
  • 测评结果:RE
  • 用时:0ms
  • 内存:0kb
  • [2024-02-25 19:22:36]
  • 提交

answer

#include<cstdio>
#include<ctime>
#include<queue>
#include<algorithm>
#define R register
using namespace std;

const int MAXN = 25;

int n, e[MAXN];
int f[1 << MAXN];
int nx[1 << MAXN];
int nd[1 << MAXN];
int ans[MAXN], start;

char str[MAXN];
inline void read(R int t) {
	scanf ("%s", str);
	for (R int i = 0; i < n; ++ i)
		if (str[i] == '1')
			e[t] |= (1 << i);
}
inline void write(bool fg) {
	if (fg) putchar('1');
	else putchar('0');
}
queue<int>q;
inline void DP() {
	f[1] = 1; 
	nx[1] = e[1];
	for (R int u = 1; u < (1 << n); ++ u) {
		if (!f[u]) continue;
		R int nxt = nx[u] & ((1 << n) - u - 1);
		for (R int i = 1; i <= n; ++ i)
			if ((1 << (i - 1)) & nxt) {
				R int v = u | (1 << (i - 1));
				if (!f[v]) f[v] = 1, q.push(v);
				nx[v] |= e[i]; nd[v] |= (1 << (i - 1));
			}
	}
}
inline void Solve() {
	ans[1] = nd[(1 << n) - 1]; putchar('0');
	for (R int i = 2; i <= n; ++ i)
		if ((ans[1] >> (i - 1)) & 1)
			ans[i] = 1, putchar('1');
		else putchar('0');
	puts("");
	for (R int i = 2; i <= n; ++ i) {
		for (R int j = 1; j < (1 << n); ++ j)
			if ((j & 1) && (nd[j] & (1 << (i - 1))))
				ans[i] |= nd[(1 << n) - j];
		for (R int j = 1; j <= n; ++ j) {
			if (i == j) putchar('0');
			else write((ans[i] >> (j - 1)) & 1);
		}
		puts("");
	}
}

int main()
{
	start = clock();
	freopen("a.in", "r", stdin);
	freopen("a.out", "w", stdout);
	scanf ("%d", &n);
	for (int i = 1; i <= n; ++ i)
		read(i);
	DP(); Solve();
	printf ("%lf\n", 1. * (clock() - start) / CLOCKS_PER_SEC);
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Dangerous Syscalls

input:

4
0110
1010
1101
0010

output:


result: