QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#500946#5523. Graph Problem With Small $n$nikatamlianiTL 0ms3808kbC++141.2kb2024-08-02 05:27:022024-08-02 05:27:02

Judging History

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

  • [2024-08-02 05:27:02]
  • 评测
  • 测评结果:TL
  • 用时:0ms
  • 内存:3808kb
  • [2024-08-02 05:27:02]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;

#ifndef ONLINE_JUDGE
#include "debug.cpp"
#else
#define debug(...)
#endif

const int N = 1e4 + 10, MOD = 998244353;


main() {
  ios::sync_with_stdio(0); cin.tie(0);

  int n; cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < n; ++j) {
      char c; cin >> c;
      if (c == '1') {
        a[i] |= 1 << j;
      }
    }
  }

  vector<int> adj(1 << n);
  for (int mask = 1; mask < (1 << n); ++mask) {
    for (int i = 0; i < n; ++i) {
      if (mask >> i & 1) {
        adj[mask] |= a[i];
      }
    }
  }

  vector<int> dp; // dp[mask][i] = can we end at i with mask, compressed tho
  for (int start = 0; start < n; ++start) {
    dp = vector<int>(1 << n);
    dp[1 << start] = 1 << start;

    for (int mask = 1; mask < (1 << n); ++mask) {
      int possible_last = dp[mask];
      int possible_next = adj[possible_last] & (~mask);
      for (int next = 0; next < n; ++next) {
        if (possible_next >> next & 1) {
          dp[mask ^ (1 << next)] |= 1 << next;
        }
      }
    }

    for (int end = 0; end < n; ++end) {
      cout << (dp.back() >> end & 1);
    }
    cout << '\n';
  }

}


詳細信息

Test #1:

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

input:

4
0110
1010
1101
0010

output:

0001
0001
0000
1100

result:

ok 4 lines

Test #2:

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

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

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: