QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#280320#5523. Graph Problem With Small $n$fryanTL 1ms3856kbC++202.1kb2023-12-09 15:08:392023-12-09 15:08:40

Judging History

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

  • [2023-12-09 15:08:40]
  • 评测
  • 测评结果:TL
  • 用时:1ms
  • 内存:3856kb
  • [2023-12-09 15:08:39]
  • 提交

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 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

int n;
v2b adj;
v2b udj;
v2i dp;

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-'0';
		}
	}
	udj = v2b(1<<n, vb(n, 0));
	for (int i = 0; i < (1<<n); i++) {
		for (int j = 0; j < n; j++) {
			if (i&(1<<j)) {
				for (int k = 0; k < n; k++) {
					udj[i][k] = udj[i][k]|adj[j][k];
				}
			}
		}
	}
	dp = v2i(n, vi(1<<n, 0));
	for (int i = 0; i < n; i++) {
		dp[i][1<<i] = 1<<i;
	}
	for (int m = 1; m < (1<<n); m++) {
		for (int s = 0; s < n; s++) {
			for (int nxt = 0; nxt < n; nxt++) {
				if (1<<(nxt)&m) continue;
				if (udj[dp[s][m]][nxt]) {
					dp[s][m + (1<<nxt)] |= (1<<nxt);
				}
			}
		}
	}
	for (int i = 0; i < n; i++) {
		int x = dp[i][(1<<n)-1];
		for (int j = 0; j < n; j++) {
			if (x&(1<<j)) cout << 1;
			else cout << 0;
		}
		cout << "\n";
	}
	return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 1ms
memory: 3856kb

input:

4
0110
1010
1101
0010

output:

0001
0001
0000
1100

result:

ok 4 lines

Test #2:

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

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

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: