QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#84166#5523. Graph Problem With Small $n$yx20220802TL 2ms3640kbC++141.9kb2023-03-05 20:42:012023-03-05 20:42:03

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-05 20:42:03]
  • 评测
  • 测评结果:TL
  • 用时:2ms
  • 内存:3640kb
  • [2023-03-05 20:42:01]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
namespace IO_ER{
	#define LL long long
	#define db double
	#define ULL unsigned long long
	#define In inline 
	#define f(a,b,i) for(int i=a;i<=b;i++)
	#define ff(a,b,i) for(int i=a;i<b;i++)
	#define f_(a,b,i) for(int i=a;i>=b;i--)
	#define ff_(a,b,i) for(int i=a;i>b;i--)
	typedef pair<int,int> Pi;
	int inf=0x3f3f3f3f;
	int INF=0x7fffffff;
	LL infll=0x3f3f3f3f3f3f3f3fll;
	LL INFll=0x7fffffffffffffffll;
	int FLAG_=0;
	char CHAR=0;
	template<typename T>void read(T &x){
		FLAG_=0;
		CHAR=getchar();
		while(CHAR<'0'||'9'<CHAR){
			if(CHAR=='-')FLAG_=1;
			CHAR=getchar();
		}
		while('0'<=CHAR&&CHAR<='9'){
			x=(x<<1)+(x<<3)+(CHAR^48);
			CHAR=getchar();
		}
		x=FLAG_?-x:x;
	} 
	template<typename T,typename ...Args>void read(T &x,Args &...args){
		read(x);
		read(args...);
	}
} 
using namespace IO_ER;

#define N 25

int n;

bitset<N>e[N];
bitset<N>dp[1<<N];

int main(){
	read(n);
	char s[N];
	f(1,n,i){
		scanf("%s",s+1);
		f(1,n,j){
			e[i-1].set(j-1,s[j]-'0');
		}
	}
//	f(1,n,i){
//		f(1,n,j){
//			cout<<e[i-1][j-1]<<" ";
//		}
//		cout<<endl;
//	}
	int mx=(1<<n)-1;
	f(1,n,st){
		f(0,mx,i)dp[i].reset();
		dp[1<<(st-1)].set(st-1,1);
//		f(0,mx,s){
//			f(1,n,i){
//				cout<<dp[s][i-1]<<" ";
//			}
//			cout<<endl;
//		}
		f(0,mx,s){
			if((s&(1<<(st-1)))==0)continue;
//			cout<<s<<endl;
			f(1,n,u){
				if((s&(1<<(u-1)))==0)continue;
//				cout<<s<<" "<<u<<" "<<(s^(1<<(u-1)))<<endl;
//				f(1,n,i){
//					cout<<dp[s^(1<<(u-1))][i-1]<<" ";
//				}
//				cout<<endl;
//				f(1,n,i){
//					cout<<e[u-1][i-1]<<" ";
//				}
//				cout<<endl;
//				cout<<endl;
				if((dp[s^(1<<(u-1))]&e[u-1]).any()){
					dp[s].set(u-1,1);
				}
			}
		}
		f(1,n,ed){
			if(dp[mx][ed-1])printf("1");
			else printf("0");
		}
//		puts("");
		puts("");
	}
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3400kb

input:

4
0110
1010
1101
0010

output:

0001
0001
0000
1100

result:

ok 4 lines

Test #2:

score: 0
Accepted
time: 0ms
memory: 3424kb

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

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: