Submission #72365

# Submission time Handle Problem Language Result Execution time Memory
72365 2018-08-26T07:29:55 Z IDxTree(#2155, TAMREF, imeimi2000, Diuven) Key of Impassable Doors (FXCUP3_key) C++17
100 / 100
41 ms 4676 KB
#include "key.h"
#include <cstdio>
#include <algorithm>
#include <vector>

using namespace std;

int n;
int isz[1001];
vector<int> ord[1001];
int nxt[1001];
int msy[1001];

namespace uf {
    int par[1001];
    int cyc[1001];
    int sz[1001];
    int find(int x) {
        if (par[x]) return par[x] = find(par[x]);
        return x;
    }
    int merge(int x, int y) {
        x = find(x);
        y = find(y);
        if (x == y) return 0;
        if (sz[x] < sz[y]) swap(x, y);
        par[y] = x;
        sz[x] += sz[y];
        return 1;
    }
}

int ch[1001];
int dfs(int x) {
    x = uf::find(x);
    if (ch[x]) return 0;
    ch[x] = 1;
    if (nxt[x]) return dfs(nxt[x]) + 1;
    return isz[x];
}

int bsearch(vector<int> &ord, int x, int s, int e) {
    if (s > e) return 0;
    int sz = 1;
    for (int i = 1; i <= n; ++i) ch[i] =  0;
    for (int i = s; i <= e; ++i) {
        sz += dfs(ord[i]);
        TakeKey(ord[i]);
    }
    TakeKey(x);
    int ret = Explore();
    return ret == sz;
}

int cycsearch(vector<int> &cyc, int x) {
    int s = 0, e = cyc.size();
    while (s < e) {
        int m = (s + e) / 2;
        for (int i = s; i <= m; ++i) TakeKey(cyc[i]);
        TakeKey(x);
        int ret = Explore();
        if (ret == (m - s + 1) * isz[x]) e = m;
        else s = m + 1;
    }
    return s;
}

void EnsureKeyInfo(int N) {
    n = N;
    for (int i = 1; i <= n; ++i) {
        TakeKey(i); ord[isz[i] = Explore()].push_back(i);
        uf::sz[i] = 1;
    }
    vector<int> pr, tp;
    for (int it = 1; it <= n; ++it) {
        vector<int> res;
        for (int i : ord[it]) {
            int s = 0, e = pr.size();
            while (s < e) {
                int m = (s + e) / 2;
                if (bsearch(pr, i, s, m)) e = m;
                else s = m + 1;
            }
            if (s != pr.size()) nxt[i] = pr[s], msy[i] = msy[pr[s]], tp.push_back(i);
            else res.push_back(i);
        }
        vector<int> cyc;
        for (int i : res) {
            int ret = cycsearch(cyc, i);
            if (ret != cyc.size()) uf::merge(cyc[ret], i), msy[i] = msy[cyc[ret]];
            else cyc.push_back(i), tp.push_back(i), msy[i] = i;
        }
        pr = tp;
        tp.clear();
    }
    
    for (int i = 1; i <= n; ++i) {
        int x = i;
        while (nxt[x]) {
            Report(i, x);
            x = nxt[x];
        }
        for (int j = 1; j <= n; ++j) {
            if (nxt[j]) continue;
            if (uf::find(msy[i]) == uf::find(j)) Report(i, j);
        }
    }
}

Compilation message

key.cpp: In function 'void EnsureKeyInfo(int)':
key.cpp:84:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
             if (s != pr.size()) nxt[i] = pr[s], msy[i] = msy[pr[s]], tp.push_back(i);
                 ~~^~~~~~~~~~~~
key.cpp:90:21: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
             if (ret != cyc.size()) uf::merge(cyc[ret], i), msy[i] = msy[cyc[ret]];
                 ~~~~^~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 612 KB Output is correct
3 Correct 2 ms 664 KB Output is correct
4 Correct 2 ms 716 KB Output is correct
5 Correct 3 ms 716 KB Output is correct
6 Correct 2 ms 716 KB Output is correct
7 Correct 2 ms 852 KB Output is correct
8 Correct 2 ms 852 KB Output is correct
9 Correct 2 ms 868 KB Output is correct
10 Correct 2 ms 868 KB Output is correct
11 Correct 3 ms 868 KB Output is correct
12 Correct 3 ms 928 KB Output is correct
13 Correct 2 ms 928 KB Output is correct
14 Correct 3 ms 1004 KB Output is correct
15 Correct 3 ms 1004 KB Output is correct
16 Correct 4 ms 1004 KB Output is correct
17 Correct 2 ms 1004 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 612 KB Output is correct
3 Correct 2 ms 664 KB Output is correct
4 Correct 2 ms 716 KB Output is correct
5 Correct 3 ms 716 KB Output is correct
6 Correct 2 ms 716 KB Output is correct
7 Correct 2 ms 852 KB Output is correct
8 Correct 2 ms 852 KB Output is correct
9 Correct 2 ms 868 KB Output is correct
10 Correct 2 ms 868 KB Output is correct
11 Correct 3 ms 868 KB Output is correct
12 Correct 3 ms 928 KB Output is correct
13 Correct 2 ms 928 KB Output is correct
14 Correct 3 ms 1004 KB Output is correct
15 Correct 3 ms 1004 KB Output is correct
16 Correct 4 ms 1004 KB Output is correct
17 Correct 2 ms 1004 KB Output is correct
18 Correct 6 ms 1900 KB Output is correct
19 Correct 5 ms 1900 KB Output is correct
20 Correct 4 ms 1900 KB Output is correct
21 Correct 5 ms 1900 KB Output is correct
22 Correct 4 ms 1900 KB Output is correct
23 Correct 7 ms 2540 KB Output is correct
24 Correct 7 ms 2556 KB Output is correct
25 Correct 8 ms 2556 KB Output is correct
26 Correct 8 ms 2556 KB Output is correct
27 Correct 8 ms 2556 KB Output is correct
28 Correct 9 ms 2556 KB Output is correct
29 Correct 8 ms 2556 KB Output is correct
30 Correct 8 ms 2556 KB Output is correct
31 Correct 8 ms 2580 KB Output is correct
32 Correct 8 ms 2596 KB Output is correct
33 Correct 7 ms 2600 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 612 KB Output is correct
3 Correct 2 ms 664 KB Output is correct
4 Correct 2 ms 716 KB Output is correct
5 Correct 3 ms 716 KB Output is correct
6 Correct 2 ms 716 KB Output is correct
7 Correct 2 ms 852 KB Output is correct
8 Correct 2 ms 852 KB Output is correct
9 Correct 2 ms 868 KB Output is correct
10 Correct 2 ms 868 KB Output is correct
11 Correct 3 ms 868 KB Output is correct
12 Correct 3 ms 928 KB Output is correct
13 Correct 2 ms 928 KB Output is correct
14 Correct 3 ms 1004 KB Output is correct
15 Correct 3 ms 1004 KB Output is correct
16 Correct 4 ms 1004 KB Output is correct
17 Correct 2 ms 1004 KB Output is correct
18 Correct 6 ms 1900 KB Output is correct
19 Correct 5 ms 1900 KB Output is correct
20 Correct 4 ms 1900 KB Output is correct
21 Correct 5 ms 1900 KB Output is correct
22 Correct 4 ms 1900 KB Output is correct
23 Correct 7 ms 2540 KB Output is correct
24 Correct 7 ms 2556 KB Output is correct
25 Correct 8 ms 2556 KB Output is correct
26 Correct 8 ms 2556 KB Output is correct
27 Correct 8 ms 2556 KB Output is correct
28 Correct 9 ms 2556 KB Output is correct
29 Correct 8 ms 2556 KB Output is correct
30 Correct 8 ms 2556 KB Output is correct
31 Correct 8 ms 2580 KB Output is correct
32 Correct 8 ms 2596 KB Output is correct
33 Correct 7 ms 2600 KB Output is correct
34 Correct 15 ms 4092 KB Output is correct
35 Correct 21 ms 4092 KB Output is correct
36 Correct 23 ms 4108 KB Output is correct
37 Correct 19 ms 4108 KB Output is correct
38 Correct 16 ms 4108 KB Output is correct
39 Correct 18 ms 4604 KB Output is correct
40 Correct 20 ms 4604 KB Output is correct
41 Correct 30 ms 4604 KB Output is correct
42 Correct 29 ms 4604 KB Output is correct
43 Correct 22 ms 4604 KB Output is correct
44 Correct 24 ms 4604 KB Output is correct
45 Correct 41 ms 4604 KB Output is correct
46 Correct 20 ms 4604 KB Output is correct
47 Correct 22 ms 4676 KB Output is correct
48 Correct 28 ms 4676 KB Output is correct
49 Correct 23 ms 4676 KB Output is correct