QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#278353#5523. Graph Problem With Small $n$fryanTL 0ms3888kbC++203.0kb2023-12-07 15:06:182023-12-07 15:06:20

Judging History

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

  • [2023-12-07 15:06:20]
  • 评测
  • 测评结果:TL
  • 用时:0ms
  • 内存:3888kb
  • [2023-12-07 15:06:18]
  • 提交

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');
		}
	}
	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;
}

详细

Test #1:

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

input:

4
0110
1010
1101
0010

output:

0001
0001
0000
1100

result:

ok 4 lines

Test #2:

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

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: 0ms
memory: 3888kb

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: