Submission #343718

# Submission time Handle Problem Language Result Execution time Memory
343718 2021-01-04T12:17:52 Z Joshc Flood (IOI07_flood) C++11
42 / 100
2000 ms 31280 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], 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]]);
    }
    multiset<int, decltype(&comp)> s(&comp);
    for (int i=1; i<=w; i++) s.insert(i);
    while (!s.empty()) {
        int start = p[*s.begin()], cur=q[*s.begin()];
        if (dir(start, cur)<2) swap(start, cur);
        int d = dir(start, cur), orig=cur;
        set<int> del = {*s.begin()};
        num[*s.begin()]++;
        while (true) {
            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(s.find(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 4972 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 4972 KB Output is correct
2 Correct 4 ms 5100 KB Output is correct
3 Correct 3 ms 4972 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 5100 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 2065 ms 5100 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 5 ms 5100 KB Output is correct
2 Execution timed out 2084 ms 5100 KB Time limit exceeded
# Verdict Execution time Memory Grader output
1 Execution timed out 2084 ms 5100 KB Time limit exceeded
# Verdict Execution time Memory Grader output
1 Correct 4 ms 5100 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 2087 ms 5100 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 2066 ms 5100 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 2075 ms 9068 KB Time limit exceeded
# Verdict Execution time Memory Grader output
1 Correct 142 ms 20588 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 2092 ms 21740 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 2057 ms 27348 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 2076 ms 31280 KB Time limit exceeded
2 Halted 0 ms 0 KB -