Submission #344362

# Submission time Handle Problem Language Result Execution time Memory
344362 2021-01-05T14:30:26 Z Joshc Flood (IOI07_flood) C++11
73 / 100
544 ms 34656 KB
#include <cstdio>
#include <algorithm>
#include <set>
#include <vector>
using namespace std;

const int MAX_N = 100001;

int x[MAX_N], y[MAX_N], p[2*MAX_N], q[2*MAX_N], m[2*MAX_N], m2[2*MAX_N], left[2*MAX_N], num[2*MAX_N];
set<pair<int, int> > edges[MAX_N];

int dir(int a, int b) {
    if (x[a] == x[b]) return y[a]<y[b] ? 0 : 2;
    return x[a]<x[b] ? 3 : 1;
}

bool comp(int a, int b) {
    if ((dir(p[a], q[a])&1) != (dir(p[b], q[b])&1)) return dir(p[b], q[b])&1;
    if (dir(p[a], q[a])&1) return y[p[a]] > y[p[b]];
    return x[p[a]] < x[p[b]];
}

int main() {
    int n, w, ans=0;
    scanf("%d", &n);
    for (int i=1; i<=n; i++) scanf("%d%d", &x[i], &y[i]);
    scanf("%d", &w);
    for (int i=1; i<=w; i++) {
        scanf("%d%d", &p[i], &q[i]);
        edges[p[i]].insert({q[i], i});
        edges[q[i]].insert({p[i], i});
        left[i] = min(x[p[i]], x[q[i]]);
    }
    vector<int> v;
    set<int> s;
    for (int i=1; i<=w; i++) {
        v.push_back(i);
        s.insert(i);
    }
    sort(v.begin(), v.end(), comp);
    for (int i=0; i<w; i++) {
        m[i+1] = v[i];
        m2[v[i]] = i+1;
    }
    while (!s.empty()) {
        int a = m[*s.begin()];
        int start = p[a], cur=q[a];
        if (dir(start, cur)<2) swap(start, cur);
        int d = dir(start, cur), orig=cur;
        set<int> del = {a};
        num[a]++;
        while (true) {
            if (!cur) break;
            int angle=4;
            pair<int, int> best;
            for (auto v : edges[cur]) {
                int x = (dir(cur, v.first)-d+5)%4;
                if (x < angle) {
                    angle = x;
                    best = v;
                }
            }
            if (cur==start && orig==best.first) break;
            num[best.second]++;
            del.insert(best.second);
            d = dir(cur, best.first);
            cur = best.first;
        }
        for (int i : del) {
            edges[p[i]].erase({q[i], i});
            edges[q[i]].erase({p[i], i});
            s.erase(m2[i]);
        }
    }
    for (int i=1; i<=w; i++) ans += num[i]==2;
    printf("%d\n", ans);
    for (int i=1; i<=w; i++) {
        if (num[i] == 2) printf("%d\n", i);
    }
}

Compilation message

flood.cpp: In function 'int main()':
flood.cpp:25:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   25 |     scanf("%d", &n);
      |     ~~~~~^~~~~~~~~~
flood.cpp:26:35: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   26 |     for (int i=1; i<=n; i++) scanf("%d%d", &x[i], &y[i]);
      |                              ~~~~~^~~~~~~~~~~~~~~~~~~~~~
flood.cpp:27:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   27 |     scanf("%d", &w);
      |     ~~~~~^~~~~~~~~~
flood.cpp:29:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   29 |         scanf("%d%d", &p[i], &q[i]);
      |         ~~~~~^~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 3 ms 5100 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 5100 KB Output is correct
2 Correct 3 ms 5100 KB Output is correct
3 Correct 4 ms 5100 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 5100 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 5100 KB Output is correct
2 Correct 4 ms 5100 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 5100 KB Output is correct
2 Correct 4 ms 5100 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 5100 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 5248 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 5100 KB Output is correct
2 Correct 5 ms 5240 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 5100 KB Output is correct
2 Correct 4 ms 5100 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 39 ms 9452 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 153 ms 21568 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 137 ms 23152 KB Output is correct
2 Runtime error 544 ms 33760 KB Memory limit exceeded
# Verdict Execution time Memory Grader output
1 Correct 382 ms 29540 KB Output is correct
2 Runtime error 434 ms 34656 KB Memory limit exceeded
# Verdict Execution time Memory Grader output
1 Runtime error 535 ms 33376 KB Memory limit exceeded
2 Halted 0 ms 0 KB -