QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#621680#9424. Stop the Castle 2IllusionaryDominanceRE 0ms0kbC++203.8kb2024-10-08 16:09:542024-10-08 16:09:55

Judging History

This is the latest submission verdict.

  • [2024-10-08 16:09:55]
  • Judged
  • Verdict: RE
  • Time: 0ms
  • Memory: 0kb
  • [2024-10-08 16:09:54]
  • Submitted

answer

#include <bits/stdc++.h>

using namespace std;

typedef pair <int, int> pii;

const int MAX_N = 200000 + 5;
const int MAX_M = 500000 + 5;

int N, M, K, tot;
struct Node{
    int x, y, id;
}node[MAX_N];
map <pii, int> idx;
unordered_set <int> edge[MAX_N], redge[MAX_N];

void Build(int x, int y) {
    edge[x].insert(y);
    redge[y].insert(x);
}

void solve() {
    for (int i = 1; i <= M; i ++) {
        edge[i].clear();
    }
    for (int i = 1; i <= tot; i ++) {
        redge[i].clear();
    }
    tot = 0; idx.clear();
    
    cin >> N >> M >> K;
    for (int i = 1; i <= N; i ++) {
        cin >> node[i].x >> node[i].y;
        node[i].id = -i;
    }
    for (int i = 1; i <= M; i ++) {
        cin >> node[i + N].x >> node[i + N].y;
        node[i + N].id = i;
    }
    auto cmp_by_x = [&](const Node &i, const Node &j) -> bool {
        return i.x < j.x || (i.x == j.x && i.y < j.y);
    };
    auto cmp_by_y = [&](const Node &i, const Node &j) -> bool {
        return i.y < j.y || (i.y == j.y && i.x < j.x);
    };
    sort(node + 1, node + N + M + 1, cmp_by_x);
    for (int l = 1, r; l <= N + M; l = r) {
        for (r = l; r <= N + M && node[l].x == node[r].x; r ++);
        for (int i = l, j; i < r; i = j) {
            for ( ; i < r && node[i].id > 0; i ++);
            for (j = i + 1; j < r && node[j].id > 0; j ++);
            if (i < r && j < r) {
                pii tmp = pair(node[i].id, node[j].id);
                auto it = idx.find(tmp); int v = -1;
                if (it == idx.end()) {
                    idx[tmp] = ++ tot; v = tot;
                }else {
                    v = it -> second;
                }
                for (int k = i + 1; k < j; k ++) {
                    Build(node[k].id, v);
                }
            }
        }
    }
    sort(node + 1, node + N + M + 1, cmp_by_y);
    for (int l = 1, r; l <= N + M; l = r) {
        for (r = l; r <= N + M && node[l].y == node[r].y; r ++);
        for (int i = l, j; i < r; i = j) {
            for ( ; i < r && node[i].id > 0; i ++);
            for (j = i + 1; j < r && node[j].id > 0; j ++);
            if (i < r && j < r) {
                pii tmp = pair(node[i].id, node[j].id);
                auto it = idx.find(tmp); int v = -1;
                if (it == idx.end()) {
                    idx[tmp] = ++ tot; v = tot;
                }else {
                    v = it -> second;
                }
                for (int k = i + 1; k < j; k ++) {
                    Build(node[k].id, v);
                }
            }
        }
    }
    
    auto Priority = [&](int u) -> int {
        if ((int)edge[u].size() < 2) return -(int)edge[u].size();
        for (auto v : edge[u]) {
            int cnt = 0;
            for (auto w : redge[v]) {
                if ((int)edge[w].size() == 2) cnt ++;
            }
            if (cnt == 1) return -3;
        }
        return -2;
    };
    
    set <pii> s;
    for (int i = 1; i <= M; i ++) {
        s.insert(pair(Priority(i), i));
    }
    
    int ans = tot;
    while ((int)s.size() > K) {
        auto it = s.begin();
        auto [priority, u] = *it;
        s.erase(it);
        for (auto v : edge[u]) {
            for (auto w : redge[v]) {
                s.erase(pair(Priority(w), w));
                edge[w].erase(v);
                s.insert(pair(Priority(w), w));
            }
            redge[v].clear();
        }
        if (priority < -1) {
            ans -= 2;
        }else if (priority) {
            ans --;
        }
    }
    cout << ans << '\n';
    for (auto [priority, u] : s) cout << u << ' ';
    cout << '\n';
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    
	int T; cin >> T;
	while (T --) solve();
    
	return 0;
}

详细

Test #1:

score: 0
Runtime Error

input:

3
8 6 4
1 3
2 1
2 6
4 1
4 7
6 1
6 3
6 6
2 3
3 1
4 3
4 6
5 2
6 4
3 2 1
10 12
10 10
10 11
1 4
1 5
1 3 2
1 1
2 1
2 2
2 3

output:


result: