Submission #868350

# Submission time Handle Problem Language Result Execution time Memory
868350 2023-10-31T07:47:50 Z josanneo22 Flood (IOI07_flood) C++17
67 / 100
318 ms 65540 KB
#pragma warning(disable : 4996)
#include<bits/stdc++.h>
using namespace std;

using ll = long long;
using pii = pair<int, int>;
#define L(i,j,k) for(int i=(j);i<=(k);i++)
#define R(i,j,k) for(int i=(j);i>=(k);i--)
#define all(x) x.begin(), x.end()
#define orz ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); 

char buf[1 << 23], * p1 = buf, * p2 = buf;
#define getchar() (p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<21,stdin),p1==p2)?EOF:*p1++)
inline int rd()
{
    int s = 0;
    char ch = getchar(), last;
    while (ch < '0' || ch>'9') last = ch, ch = getchar();
    while (ch >= '0' && ch <= '9') s = (s << 1) + (s << 3) + (ch ^ 48), ch = getchar();
    return last == '-' ? -s : s;
}
int num[100];
inline void rt(int x)
{
    if (x < 0) putchar('-'), x = -x;;
    int len = 0;
    do num[len++] = x % 10; while (x /= 10);
    while (len--) putchar(num[len] + '0');
}

const int N = 2e5 + 500;
int n, x[N], y[N], to[N][4], dr[N][4], m;
vector<pii> g[N*2];
inline int orientation(int a, int b) {
    if (y[a] == y[b]) return x[a] > x[b];
    return 2 + (y[a] > y[b]);
}
inline void add_edge(int u, int v, int w) {
    g[u].push_back(make_pair(v, w)); 
    g[v].push_back(make_pair(u, w)); 
}
int main() {
    orz;
    n = rd();
    L(i, 1, n) x[i] = rd(), y[i] = rd();
    m = rd();
    L(i, 1, m) {
        int u = rd(), v = rd();
        dr[u][orientation(u, v)] = dr[v][orientation(v, u)] = i;
        to[u][orientation(u, v)] = v; to[v][orientation(v, u)] = u;
        add_edge(i, i + m, 1);
    }
    L(i, 1, n) {
        vector<int> p;
        if (dr[i][0])p.push_back(0);
        if (dr[i][2])p.push_back(2);
        if (dr[i][1])p.push_back(1);
        if (dr[i][3])p.push_back(3);
        if (p.size() == 0) continue;
        for (int j = 0; j + 1 < p.size(); j++) {
            int u = p[j], v = p[j + 1];
            add_edge(dr[i][u] + (u == 1 || u == 2) * m, dr[i][v] + (v == 0 || v == 3) * m, 0);
        }
        int u = p.back(), v = p.front();
        add_edge(dr[i][u] + (u == 1 || u == 2) * m, dr[i][v] + (v == 0 || v == 3) * m, 0);
    }

    vector<int> vis(N), dis(N, 1E9);
    int S = 0, mxy = -1;
    function<void(int)> dye = [&](int u) {
        vis[u] = true;
        L(i, 0, 3) {
            if (dr[u][i]==0)continue;
            if ((i == 0 || i == 2) && y[u] > mxy) {
                mxy = y[u];  S = dr[u][i];
            }
            if (!vis[to[u][i]]) dye(to[u][i]);
        }
        };
    function<void()> bfs = [&]() {
        deque<int>q;
        q.push_back(S), dis[S] = 0;
        while (!q.empty()) {
            int u = q.front(); q.pop_front();
            for (auto& [v, w] : g[u]) {
                if (dis[v] <= dis[u] + w)continue;
                dis[v] = dis[u] + w;
                if (w) q.push_back(v);
                else q.push_front(v);
            }
        }
        };
    L(i, 1, n) {
        if (vis[i]) continue;
        S = 0; mxy = -1; dye(i);
        if (S) bfs();
    }
    int ans = 0;
    L(i, 1, m) ans += (dis[i] != 5 && dis[i] == dis[i + m]);
    printf("%d\n", ans);
    L(i, 1, m) if (dis[i] == dis[i + m]) printf("%d\n", i);
}

Compilation message

flood.cpp:1: warning: ignoring '#pragma warning ' [-Wunknown-pragmas]
    1 | #pragma warning(disable : 4996)
      | 
flood.cpp: In function 'int main()':
flood.cpp:60:31: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   60 |         for (int j = 0; j + 1 < p.size(); j++) {
      |                         ~~~~~~^~~~~~~~~~
flood.cpp: In function 'int rd()':
flood.cpp:20:24: warning: 'last' may be used uninitialized in this function [-Wmaybe-uninitialized]
   20 |     return last == '-' ? -s : s;
      |            ~~~~~~~~~~~~^~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 3 ms 18524 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 18520 KB Output is correct
2 Correct 4 ms 18524 KB Output is correct
3 Correct 4 ms 18540 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 18524 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 18524 KB Output is correct
2 Correct 4 ms 18524 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 18524 KB Output is correct
2 Correct 4 ms 18596 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 18680 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 18524 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 18520 KB Output is correct
2 Incorrect 4 ms 18520 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 4 ms 18524 KB Output is correct
2 Incorrect 4 ms 18524 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 13 ms 20572 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 38 ms 32084 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 35 ms 31052 KB Output is correct
2 Runtime error 276 ms 65536 KB Execution killed with signal 9
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 318 ms 65536 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 275 ms 65540 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -