답안 #868316

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
868316 2023-10-31T04:57:20 Z josanneo22 Flood (IOI07_flood) C++17
10 / 100
178 ms 43348 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); 

const int N = 4e5 + 500;
int n, x[N], y[N], to[N][4], dr[N][4], m;
vector<pii> g[N];
int orientation(int a, int b) {
    if (y[a] == y[b]) return x[a] > x[b];
    return 2 + (y[a] > y[b]);
}
void add_edge(int u, int v, int w) { 
    //cout << u << ' ' << v << '\n';
    g[u].push_back(make_pair(v, w)); 
    g[v].push_back(make_pair(u, w)); 
}
int main() {
    orz;
    cin >> n;
    L(i, 1, n) cin >> x[i] >> y[i];
    cin >> m;
    L(i, 1, m) {
        int u, v; cin >> u >> v;
        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() <= 1) continue;
        //cout << "available directions: "; for (auto& x : p) cout << x << ' ';
        //cout << '\n';
        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]!=1E9 && dis[i] == dis[i + m]);
   // L(i, 1, 2 * m) cout << dis[i] << ' ';
    //cout << '\n';
    cout << ans << '\n';
    L(i, 1, m) if (dis[i] == dis[i + m]) cout << i << '\n';
}

Compilation message

flood.cpp:1: warning: ignoring '#pragma warning ' [-Wunknown-pragmas]
    1 | #pragma warning(disable : 4996)
      | 
flood.cpp: In function 'int main()':
flood.cpp:44:31: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   44 |         for (int j = 0; j + 1 < p.size(); j++) {
      |                         ~~~~~~^~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 20060 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 4 ms 20060 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 5 ms 20060 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 5 ms 20056 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 5 ms 20060 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 4 ms 20060 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 6 ms 20056 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 5 ms 20056 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 6 ms 20060 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 21 ms 22280 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 50 ms 33412 KB Memory limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 53 ms 32596 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 156 ms 39016 KB Memory limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 178 ms 43348 KB Memory limit exceeded
2 Halted 0 ms 0 KB -