QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#404745 | #5523. Graph Problem With Small $n$ | ucup-team173 | WA | 1ms | 3492kb | C++14 | 1.2kb | 2024-05-04 16:40:51 | 2024-05-04 16:40:53 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
const int maxn=24;
int n;
int to[maxn];
int f[1<<maxn];
int ans[maxn];
void solve(){
cin>>n;
for(int i=0;i<n;i++){
string s;
cin>>s;
for(int j=0;j<n;j++){
int c=s[j]-'0';
if(c){
to[i]+=(1<<j);
}
}
// cout<<to[i]<<"\n";
}
f[1<<0]=1<<0;
for(int s=1;s<(1<<n);s+=2){
int tmp=f[s];
if(tmp){
for(int i=0;i<n;i++){
if(!(s>>i&1)&&(to[i]&tmp)){
f[s|(1<<i)]|=(1<<i);
}
}
}
// cout<<s<<" "<<f[s]<<"\n";
}
int all=(1<<n)-1;
for(int s=1;s<(1<<n);s+=2){
int t=all-s+1;
for(int i=0;i<n;i++){
if(f[s]>>i&1){
ans[i]|=f[t];
}
}
}
ans[0]=f[all];
for(int i=0;i<n;i++){
for(int j=0;j<n;j++){
cout<<(ans[i]>>j&1)<<" \n"[j+1==n];
}
}
}
int main(){
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int t=1;
// cin>>t;
while(t--){
solve();
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 1ms
memory: 3492kb
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'