QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#551734#9246. Dominating Pointucup-team3877#AC ✓703ms155248kbC++205.1kb2024-09-07 17:56:522024-11-22 18:40:13

Judging History

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

  • [2024-11-22 18:40:13]
  • 自动重测本题所有获得100分的提交记录
  • 测评结果:AC
  • 用时:703ms
  • 内存:155248kb
  • [2024-11-22 18:38:25]
  • hack成功,自动添加数据
  • (/hack/1238)
  • [2024-09-07 17:56:52]
  • 评测
  • 测评结果:100
  • 用时:679ms
  • 内存:155336kb
  • [2024-09-07 17:56:52]
  • 提交

answer

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

#include <algorithm>

#include <algorithm>
#include <utility>
#include <vector>

namespace atcoder {
namespace internal {

template <class E> struct csr {
    std::vector<int> start;
    std::vector<E> elist;
    csr(int n, const std::vector<std::pair<int, E>>& edges)
        : start(n + 1), elist(edges.size()) {
        for (auto e : edges) {
            start[e.first + 1]++;
        }
        for (int i = 1; i <= n; i++) {
            start[i] += start[i - 1];
        }
        auto counter = start;
        for (auto e : edges) {
            elist[counter[e.first]++] = e.second;
        }
    }
};

// Reference:
// R. Tarjan,
// Depth-First Search and Linear Graph Algorithms
struct scc_graph {
  public:
    scc_graph(int n) : _n(n) {}

    int num_vertices() { return _n; }

    void add_edge(int from, int to) { edges.push_back({from, {to}}); }

    // @return pair of (# of scc, scc id)
    std::pair<int, std::vector<int>> scc_ids() {
        auto g = csr<edge>(_n, edges);
        int now_ord = 0, group_num = 0;
        std::vector<int> visited, low(_n), ord(_n, -1), ids(_n);
        visited.reserve(_n);
        auto dfs = [&](auto self, int v) -> void {
            low[v] = ord[v] = now_ord++;
            visited.push_back(v);
            for (int i = g.start[v]; i < g.start[v + 1]; i++) {
                auto to = g.elist[i].to;
                if (ord[to] == -1) {
                    self(self, to);
                    low[v] = std::min(low[v], low[to]);
                } else {
                    low[v] = std::min(low[v], ord[to]);
                }
            }
            if (low[v] == ord[v]) {
                while (true) {
                    int u = visited.back();
                    visited.pop_back();
                    ord[u] = _n;
                    ids[u] = group_num;
                    if (u == v) break;
                }
                group_num++;
            }
        };
        for (int i = 0; i < _n; i++) {
            if (ord[i] == -1) dfs(dfs, i);
        }
        for (auto& x : ids) {
            x = group_num - 1 - x;
        }
        return {group_num, ids};
    }

    std::vector<std::vector<int>> scc() {
        auto ids = scc_ids();
        int group_num = ids.first;
        std::vector<int> counts(group_num);
        for (auto x : ids.second) counts[x]++;
        std::vector<std::vector<int>> groups(ids.first);
        for (int i = 0; i < group_num; i++) {
            groups[i].reserve(counts[i]);
        }
        for (int i = 0; i < _n; i++) {
            groups[ids.second[i]].push_back(i);
        }
        return groups;
    }

  private:
    int _n;
    struct edge {
        int to;
    };
    std::vector<std::pair<int, edge>> edges;
};

}  // namespace internal

}  // namespace atcoder

#include <cassert>
#include <vector>

namespace atcoder {

struct scc_graph {
  public:
    scc_graph() : internal(0) {}
    scc_graph(int n) : internal(n) {}

    void add_edge(int from, int to) {
        int n = internal.num_vertices();
        assert(0 <= from && from < n);
        assert(0 <= to && to < n);
        internal.add_edge(from, to);
    }

    std::vector<std::vector<int>> scc() { return internal.scc(); }

  private:
    internal::scc_graph internal;
};

}  // namespace atcoder

using namespace atcoder;
using ll = long long;
#define fix(x) fixed << setprecision(x)
#define asc(x) x, vector<x>, greater<x>
#define rep(i, n) for(int i = 0; i < n; ++i)
#define all(x) (x).begin(),(x).end()
template<class T>bool chmin(T&a, const T&b){if(a>b){a=b;return 1;}return 0;}
template<class T>bool chmax(T&a, const T&b){if(a<b){a=b;return 1;}return 0;}
constexpr ll INFLL = (1LL << 62), MOD = 998244353;
constexpr int INF = (1 << 30);

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    scc_graph g(n);
    vector<bitset<5000>> s(n);
    rep(i,n){
        string t;
        cin >> t;
        reverse(all(t));
        s[i] = bitset<5000>(t);
        rep(j,n){
            if(s[i][j]) g.add_edge(i,j);
        }
    }
    auto h = g.scc()[0];
    vector<int> dist(n,INF);
    queue<int> que;
    que.push(h[0]);
    int d;
    dist[h[0]] = 0;
    while(que.size()){
        int now = que.front();
        d = dist[now];
        que.pop();
        for(int x:h){
            if(!s[now][x]) continue;
            if(chmin(dist[x], dist[now]+1)){
                que.push(x);
            }
        }
    }
    sort(all(h), [&](int i, int j){
        return dist[i] > dist[j];
    });
    
    vector<int> ans;
    for(int x:h){
        auto bit = s[x];
        rep(j,n){
            if(s[x][j]) bit |= s[j];
        }
        bool f = true;
        rep(j,n){
            if(x!=j && !bit[j]) f = false, j = n;
        }
        if(f) ans.emplace_back(x);
        if(dist[x]<d-2) break;
        if(ans.size()>=3) break;
    }
    if(ans.size()<3){
        cout << "NOT FOUND\n";
    }else{
        for(int x:ans) cout << x+1 << " ";
        cout << '\n';
    }
    return 0;
}

这程序好像有点Bug,我给组数据试试?

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

6
011010
000101
010111
100001
010100
100010

output:

4 6 3 

result:

ok OK, Answer correct.

Test #2:

score: 0
Accepted
time: 1ms
memory: 3580kb

input:

3
011
001
000

output:

NOT FOUND

result:

ok OK, Answer correct.

Test #3:

score: 0
Accepted
time: 1ms
memory: 3636kb

input:

3
010
001
100

output:

3 2 1 

result:

ok OK, Answer correct.

Test #4:

score: 0
Accepted
time: 533ms
memory: 154456kb

input:

4994
0100001010011001010101110010101000111101111100100001110010000111100000000100110100101000001010100000010010010110110110111010010010100110100000110110111001010111010111010111011001000101001000010001010111110000000100001100000111100011001010010111011100111010101110011000010111101011111110001111110...

output:

3967 2078 2079 

result:

ok OK, Answer correct.

Test #5:

score: 0
Accepted
time: 472ms
memory: 154128kb

input:

4994
0000000110000010100001001010100101010001000000011001110000111011100010100100001001011100000101100000100100001101101101010010110011101100101001100101110010001111110111001101000110111001010011101001010101000000111101101111001011111011000001110010000000110101010010010100100101111111001000111111011...

output:

2780 2752 2756 

result:

ok OK, Answer correct.

Test #6:

score: 0
Accepted
time: 508ms
memory: 153324kb

input:

4995
0010100011010011000010101100100000011100110100010101010101000001011110100010001001011001100001111100011010001110011101111001110001000000101010001000010000010001011010010001100001010111011111011011110110000101001000000100000000000010111010101111111100001010001000000001001110000110011001111001111...

output:

2823 2790 2791 

result:

ok OK, Answer correct.

Test #7:

score: 0
Accepted
time: 481ms
memory: 155072kb

input:

4998
0011100111111001011100001111010010000111001110101001001011010111100010001110000001000010011011011110001110101111010011000101001101001000100110111110001001100111111000010101010101000110011100011001010110111110000100000010000101001000100011000010101111101101000000101010100111010101111101111100010...

output:

2795 2775 2777 

result:

ok OK, Answer correct.

Test #8:

score: 0
Accepted
time: 464ms
memory: 154928kb

input:

4994
0010111010011101101110001111100011010010010000101101110110110000100010000101011100000001011100010001000011010101011111100011010000010110000011110010011000101011100011110110011101110000101100111110000110100111001101000100011001001001100001101110001100111011100111001011001011010111111001001000010...

output:

3973 3984 3983 

result:

ok OK, Answer correct.

Test #9:

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

input:

1
0

output:

NOT FOUND

result:

ok OK, Answer correct.

Test #10:

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

input:

2
01
00

output:

NOT FOUND

result:

ok OK, Answer correct.

Test #11:

score: 0
Accepted
time: 441ms
memory: 154900kb

input:

4998
0101101111101110111110111111111111111101111111010110100111111101110101111101111110101111011111100010111011110100111111111101011101101100110111101110110101101110111011001111101011111101111001111101011111100110111110010011010111101111011010110101011111101011101110111111101101011111010010110101111...

output:

4796 1681 1411 

result:

ok OK, Answer correct.

Test #12:

score: 0
Accepted
time: 602ms
memory: 155248kb

input:

4998
0000001000000000010000100001001010101010000010010100000100000010100000100000100010011101010000000010000101101001001101100010100000000000010011010110000001011000000000010011000000100100010000000000000100110001010110010111000010000001100110110000100010001001100010001000010000011110001011000000100...

output:

685 2307 4716 

result:

ok OK, Answer correct.

Test #13:

score: 0
Accepted
time: 623ms
memory: 154400kb

input:

4998
0010101101011111101011000011111010001110000110101111101010010010111111010111101100001111110111010111000111111011111011110011111101010001111000000101110101000111111100100000011000010011110101010100011000000010100011011011000101101010010100110000000101001000111010101010001110101011011001100011100...

output:

1529 2253 3540 

result:

ok OK, Answer correct.

Test #14:

score: 0
Accepted
time: 703ms
memory: 153176kb

input:

5000
0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000...

output:

4999 5000 1 

result:

ok OK, Answer correct.

Extra Test:

score: 0
Extra Test Passed