QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#411682#5523. Graph Problem With Small $n$DYSisNoobWA 0ms3612kbC++141.1kb2024-05-15 17:50:332024-05-15 17:50:33

Judging History

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

  • [2024-05-15 17:50:33]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3612kb
  • [2024-05-15 17:50:33]
  • 提交

answer

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

int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	
	int n;
	cin >> n;
	vector<int> m(n + 1), vis(1 << n), dp(1 << n), ans(n + 1);
	for (int i = 1; i <= n; i++)
	{
		for (int j = 1; j <= n; j++)
		{
			char tmp = getchar();
			if (tmp == '1')  m[i] += (1 << (j - 1));
		}
		getchar();
	}
	dp[1] = 1;
	queue<int> q;
	q.push(1);
	while (!q.empty())
	{
		int cur = q.front();
		q.pop();
		if (vis[cur])  continue;
		vis[cur] = 1;
		for (int i = 1; i <= n; i++)
		{
			if (!(cur & (1 << (i - 1))) && (dp[cur] & m[i]))
			{
				dp[cur + (1 << (i - 1))] |= (1 << (i - 1));
				q.push(cur + (1 << (i - 1)));
			}
		}
	}
	for (int i = 1; i <= n; i++)
	{
		for (int j = 0; j < (1 << n); j++)
		{
			if (!(j & (1 << (i - 1))) || !(j & 1) || !(dp[j] & (1 << (i - 1))))  continue;
			ans[i] |= dp[(1 << n) - j];
		}
	}
	for (int i = 1; i <= n; i++)
	{
		int cnt = 0;
		while (ans[i])
		{
			cout << (ans[i] & 1);
			ans[i] >>= 1;
			cnt++;
		}
		for (int j = cnt + 1; j <= n; j++)
		{
			cout << 0;
		}
		cout << '\n';
	}
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 0ms
memory: 3612kb

input:

4
0110
1010
1101
0010

output:

0000
0000
0000
0000

result:

wrong answer 1st lines differ - expected: '0001', found: '0000'