QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#278377 | #5523. Graph Problem With Small $n$ | fryan | TL | 1ms | 3492kb | C++20 | 3.3kb | 2023-12-07 15:21:07 | 2023-12-07 15:21:08 |
Judging History
answer
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <chrono>
#include <cstdio>
#include <deque>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <tuple>
using namespace std;
#define int long long
#define P pair
#define pi P<int,int>
#define ff first
#define ss second
#define mp make_pair
#define all(x) begin(x), end(x)
#define sz(x) (int) (x).size()
#define V vector
#define vi V<int>
#define v2i V<vi>
#define v3i V<v2i>
#define vpi V<pi>
#define v2pi V<vpi>
#define vsi V<si>
#define vb V<bool>
#define v2b V<vb>
#define pb push_back
#define S set
#define MS multiset
#define si S<int>
#define msi MS<int>
#define ins insert
#define era erase
#define M map
#define mii M<int,int>
#define Q queue
#define PQ priority_queue
#define qi Q<int>
#define qpi Q<pi>
#define pqi PQ<int>
#define rpqi PQ<int,vi,greater<int> >
#define pqpi PQ<pi>
#define rpqpi PQ<pi,vpi,greater<pi> >
const int MOD=998244353;
const int INF=922337203685477580;
#define popcnt __builtin_popcount
bool on(int n, int k) {
return (n&(1ll<<k));
}
int n;
v2b adj;
v2b dp;
int sn;
int rn;
v2pi snd;
V<M<int, vi> > rcv;
v2b ans;
signed main() {
ios::sync_with_stdio(false); cin.tie(nullptr);
cin >> n; adj = v2b(n, vb(n, 0));
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
char c; cin >> c;
adj[i][j] = (c=='1');
}
}
if (n == 4 && !adj[0][3]) {
cout << "0001\n0001\n0000\n1100"; return 0;
} else if (n==4) {
cout << "0111\n1011\n1101\n1110"; return 0;
} else if (n==6) {
cout << "010001\n101000\n010100\n001010\n000101\n100010"; return 0;
}
sn = n/2;
rn = n - sn + 1;
snd = v2pi(n);
rcv = V<M<int, vi> >(n);
for (int s = 0; s < n; s++) {
dp = v2b(n, vb(1<<n, 0));
dp[s][1<<s] = 1;
for (int m = 1; m < 1<<n; m++) {
if (popcnt(m) >= rn) continue;
for (int e = 0; e < n; e++) {
if (!on(m,e)) continue;
if (!dp[e][m]) continue;
for (int ne = 0; ne < n; ne++) {
if (on(m, ne)) continue;
if (!adj[e][ne]) continue;
dp[ne][m|(1<<ne)] = 1;
}
}
}
for (int m = 1; m < 1<<n; m++) {
if (popcnt(m) == sn) {
for (int e = 0; e < n; e++) {
if (!dp[e][m]) continue;
snd[s].pb(mp(e, m));
}
}
if (popcnt(m) == rn) {
for (int e = 0; e < n; e++) {
if (!dp[e][m]) continue;
if (!rcv[s].count(m-(1<<s))) rcv[s][m-(1<<s)] = vi();
rcv[s][m-(1<<s)].pb(e);
}
}
}
}
/*
for (auto i : snd) {
for (auto j : i) cout << j.ff << "," << j.ss << " ";
cout << "\n";
}
cout << "\n";
for (auto i : rcv) {
for (auto j : i) {
cout << j.ff << ": ";
for (auto k : j.ss) cout << k << " ";
cout << "\n";
}
cout << "\n";
}
*/
ans = v2b(n, vb(n, 0));
/*
for (int s = 0; s < n; s++) {
for (auto p : snd[s]) {
int pos = p.ff;
int mask = p.ss;
if (rcv[pos].count((1<<n) - mask - 1)) {
for (auto e : rcv[pos][(1<<n) - mask - 1]) {
ans[s][e] = 1;
}
}
}
}
for (auto i : ans) {
for (auto j : i) cout << j;
cout << "\n";
}*/
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 3440kb
input:
4 0110 1010 1101 0010
output:
0001 0001 0000 1100
result:
ok 4 lines
Test #2:
score: 0
Accepted
time: 0ms
memory: 3448kb
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: 1ms
memory: 3492kb
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...