QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#84708#5523. Graph Problem With Small $n$xixikeWA 2ms5500kbC++141.1kb2023-03-06 17:32:322023-03-06 17:32:32

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 17:32:32]
  • 评测
  • 测评结果:WA
  • 用时:2ms
  • 内存:5500kb
  • [2023-03-06 17:32:32]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std;

const int N = 30;
int n;
char s[N];
int to[N], sta[(1 << 24) + 10];
int f[(1 << 24) + 10]; 
int ans[N];

signed main(){
	cin >> n;
	for(int i = 1; i <= n; ++i){
		cin >> (s + 1);
		for(int j = 1; j <= n; ++j)
			if(s[j] == '1') to[i] |= (1 << (j - 1)); // i 能到达的点集 
	}
	for(int s = 0; s < (1 << n); ++s)
		for(int i = 1; i <= n; ++i)
			if((s & (1 << (i - 1)))) sta[s] |= to[i]; // 集合 s 能到达的点集 

	int all = (1 << n) - 1; 
	f[1] = 1; // f[s] 经过 s 集合可能的终点集合 
	for(int s = 1; s < (1 << n); s += 2){
		int t = sta[f[s]] & (all ^ s);
		for(int i = 1; i <= n; ++i)
			if(t & (1 << (i - 1))){
			f[s | (1 << (i - 1))] |= (1 << (i - 1));
			}
	}
//	for(int s = 1; s <= all; s += 2) cout << f[s] << " ";
//	cout << endl;
	for(int s = 1; s <= all; s += 2){
		for(int i = 1; i <= n; ++i)
			if(f[s] & (1 << (i - 1))) ans[i] |= f[(all ^ s) | 1];
	}
	for(int i = 1; i <= n; ++i){
		for(int j = 1; j <= n; ++j) cout << ((ans[i] >> (j - 1)) & 1) << ' ';
		cout << '\n';
	}
	return 0;
}
/*
4
0110
1010
1101
0010

*/

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 2ms
memory: 5500kb

input:

4
0110
1010
1101
0010

output:

0 0 0 1 
0 0 0 1 
0 0 0 0 
1 1 0 0 

result:

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