QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#281338 | #5523. Graph Problem With Small $n$ | fryan | TL | 0ms | 3640kb | C++20 | 2.4kb | 2023-12-10 02:56:38 | 2023-12-10 02:56:38 |
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 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;
vi dp;
vi ans;
void o(int c) {
for (int i = 0; i < n; i++) {
if ((1<<i)&c) cout << 1;
else cout << 0;
}
}
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];
}
}
}
}
if (n > 10) return 0;
dp = vi(1<<n, 0); dp[1] = 1;
for (int m = 1; m < (1<<n); m++) {
for (int nxt = 0; nxt < n; nxt++) {
if (1<<(nxt)&m) continue;
if (udj[dp[m]][nxt]) {
dp[m + (1<<nxt)] |= (1<<nxt);
}
}
}
ans = vi(n, 0);
for (int m = 1; m < (1<<n); m++) {
int mask = m;
int cmpl = (1<<n) - 1 - mask;
cmpl -= cmpl%2;
mask -= mask%2;
mask += 1; cmpl += 1;
if (dp[cmpl] == 0 || dp[mask] == 0) continue;
for (int i = 0; i < n; i++) {
if ((1<<i)&dp[mask]) {
ans[i] |= dp[cmpl];
}
}
}
//return 0;
for (int i = 0; i < n; i++) {
if ((1<<i)&ans[i]) {
ans[i] -= (1<<i);
}
o(ans[i]);
cout << "\n";
}
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 3640kb
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: 3576kb
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...