QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#136989#1142. Fountain Parksbashkort#0 682ms75080kbC++202.8kb2023-08-09 16:25:342024-07-04 01:26:02

Judging History

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

  • [2024-07-04 01:26:02]
  • 评测
  • 测评结果:0
  • 用时:682ms
  • 内存:75080kb
  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-08-09 16:25:34]
  • 提交

answer

#include "parks.h"
#include <bits/stdc++.h>

using namespace std;
using ll = long long;

struct DSU {
    vector<int> fa;

    void init(int n) {
        fa.resize(n);
        iota(fa.begin(), fa.end(), 0);
    }

    int find(int x) {
        return x == fa[x] ? x : fa[x] = find(fa[x]);
    }

    bool unite(int x, int y) {
        x = find(x), y = find(y);
        if (x == y) {
            return false;
        }
        fa[y] = x;
        return true;
    }
};

int construct_roads(std::vector<int> x, std::vector<int> y) {
    int n = size(x);

    map<pair<int, int>, int> mp;
    map<pair<int, int>, vector<int>> adj;

    for (int i = 0; i < n; ++i) {
        mp[{x[i], y[i]}] = i;
    }

    DSU dsu;
    dsu.init(n);
    vector<pair<int, int>> e, f;

    for (int i = 0; i < n; ++i) {
        for (int t : {0, 1}) {
            for (int d : {-2, 2}) {
                int nx = x[i] + t * d;
                int ny = y[i] + (1 - t) * d;
                if (mp.count({nx, ny})) {
                    int j = mp[{nx, ny}];
                    if (dsu.unite(i, j)) {
                        e.emplace_back(i, j);
                    }
                }
            }
        }
    }

    if (size(e) != n - 1) {
        return false;
    }

    for (int i = 0; i < size(e); ++i) {
        int nx = x[e[i].first] + x[e[i].second] >> 1;
        int ny = y[e[i].first] + y[e[i].second] >> 1;
        if (nx % 2 == 0) {
            adj[{nx - 1, ny}].push_back(~i);
            adj[{nx + 1, ny}].push_back(i);
        } else {
            adj[{nx, ny - 1}].push_back(~i);
            adj[{nx, ny + 1}].push_back(i);
        }
    }

    vector<int> type(n - 1);
    queue<int> q;
    type[0] = 1;
    q.push(0);

    while (!q.empty()) {
        int i = q.front();
        q.pop();
        int nx = x[e[i].first] + x[e[i].second] >> 1;
        int ny = y[e[i].first] + y[e[i].second] >> 1;
        if (nx % 2 == 0) {
            nx += type[i];
        } else {
            ny += type[i];
        }
        for (int to : adj[{nx, ny}]) {
            int t = to >= 0 ? 1 : -1;
            if (t == -1) {
                to = ~to;
            }
            if (to == i) {
                continue;
            }
            if (type[to] == 0) {
                type[to] = -t;
                q.push(to);
            } else {
                assert(type[to] != t);
            }
        }
    }

    vector<int> u(n - 1), v(n - 1), a(n - 1), b(n - 1);

    for (int i = 0; i < size(e); ++i) {
        u[i] = e[i].first;
        v[i] = e[i].second;
        a[i] = x[u[i]] + x[v[i]] >> 1;
        b[i] = y[u[i]] + y[v[i]] >> 1;
        if (a[i] % 2 == 0) {
            a[i] += type[i];
        } else {
            b[i] += type[i];
        }
    }

    build(u, v, a, b);

    return 1;
}

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 0
Runtime Error

Test #1:

score: 0
Runtime Error

input:

ba73dbf9c7d5e5202834d6a500541c
1
2 2

output:

Unauthorized output

result:


Subtask #2:

score: 0
Skipped

Dependency #1:

0%

Subtask #3:

score: 0
Skipped

Dependency #2:

0%

Subtask #4:

score: 0
Wrong Answer

Test #82:

score: 0
Wrong Answer
time: 1ms
memory: 3740kb

input:

ba73dbf9c7d5e5202834d6a500541c
3
200000 2
200000 4
199998 2

output:

3kr2yac8xnf3ktgcoqviaw115df6rra7is6p5uix
OK
1
2
0 1 200001 3
0 2 199999 2

result:

wrong answer b[1] = 2 is not an odd integer

Subtask #5:

score: 0
Wrong Answer

Test #108:

score: 0
Wrong Answer
time: 682ms
memory: 75080kb

input:

ba73dbf9c7d5e5202834d6a500541c
200000
82422 100002
100002 52498
82816 2
97624 2
100002 58032
20638 100002
100002 7646
80512 2
2 10584
28426 100002
2 83036
2 64556
47872 100002
55196 2
85350 100002
2 95376
2 23942
12488 100002
83178 2
2 9086
85598 2
100002 78820
100002 10868
98810 2
84182 100002
2 71...

output:

3kr2yac8xnf3ktgcoqviaw115df6rra7is6p5uix
OK
1
199999
0 148989 82421 100003
0 168975 82423 100002
1 67645 100002 52497
1 117727 100002 52499
2 150926 82815 2
2 142334 82817 2
3 164963 97623 2
3 141442 97625 2
4 9204 100002 58031
4 66537 100002 58033
5 106842 20637 100002
5 10116 20639 100002
6 182160...

result:

wrong answer b[1] = 100002 is not an odd integer

Subtask #6:

score: 0
Skipped

Dependency #1:

0%