답안 #636814

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
636814 2022-08-30T09:11:04 Z Spade1 Flood (IOI07_flood) C++14
42 / 100
120 ms 52300 KB
#include<bits/stdc++.h>
#define pii pair<int, int>
#define pll pair<long long, long long>
#define ll long long
#define ld long double
#define st first
#define nd second
#define pb push_back
#define INF INT_MAX
using namespace std;

const int N = 1e5 + 10;
int n, m;

pii c[N][4]; // right, down, left, up
bool vis[N][4], vis2[2*N];
int order[N];

pii pt[N];
int cnt = 0;
vector<int> adj[2*N];
set<int> adj2[2*N];
int dis[2*N];
vector<int> passed;
bool outer = 1;
vector<int> outer_list;

void dfs(int i, int dir) {
    for (int j = -1; j <= 2; ++j) {
        int cur = (dir+j+4)%4;
        if (c[i][cur].st && vis[i][cur]) return;
        else if (c[i][cur].st) {
            vis[i][cur] = 1;
            if (vis2[c[i][cur].nd]) outer = 0;
            passed.pb(c[i][cur].nd);
            dfs(c[i][cur].st, cur);
            adj[c[i][cur].nd].pb(cnt);
            return;
        }
    }
}

bool cmp(int i, int j) {
    if (pt[i].nd == pt[j].nd) return pt[i].st < pt[j].st;
    return pt[i].nd < pt[j].nd;
}

void solve() {
    cin >> n;
    for (int i = 1; i <= n; ++i) cin >> pt[i].st >> pt[i].nd;
    cin >> m;
    for (int i = 1; i <= m; ++i) {
        int a, b; cin >> a >> b;
        if (pt[a].st == pt[b].st) {
            if (pt[a].nd > pt[b].nd) {
                c[a][1].st = b, c[b][3].st = a;
                c[a][1].nd = i, c[b][3].nd = i;
            }
            else {
                c[a][3].st = b, c[b][1].st = a;
                c[a][3].nd = i, c[b][1].nd = i;
            }
        }
        else {
            if (pt[a].st > pt[b].st) {
                c[a][2].st = b, c[b][0].st = a;
                c[a][2].nd = i, c[b][0].nd = i;
            }
            else {
                c[a][0].st = b, c[b][2].st = a;
                c[a][0].nd = i, c[b][2].nd = i;
            }
        }
    }
    for (int i = 1; i <= n; ++i) order[i] = i;
    sort(order+1, order+n+1, cmp);
    int dir = 3;
    for (int i = 1; i <= n; ++i) {
        for (int j = -1; j <= 2; ++j) {
            int cur = (dir+j+4)%4;
            if (c[order[i]][cur].st && vis[order[i]][cur]) break;
            else if (c[order[i]][cur].st) {
                cnt++;
                int idx = passed.size();
                outer = 1;
                dfs(order[i], cur);
                for (int k = idx; k < passed.size(); ++k) {
                    vis2[passed[k]] = 1;
                }
                if (outer) outer_list.pb(cnt);
                break;
            }
        }
    }

    for (int i = 1; i <= m; ++i) {
        adj2[adj[i][0]].insert(adj[i][1]);
        adj2[adj[i][1]].insert(adj[i][0]);
    }
    queue<int> q;
    for (auto i : outer_list) {
        q.push(i);
        dis[i] = 1;
    }
    while (!q.empty()) {
        int i = q.front(); q.pop();
        for (auto j : adj2[i]) {
            if (dis[j] == 0) {
                dis[j] = dis[i] + 1;
                q.push(j);
            }
        }
    }
    vector<int> ans;
    for (int i = 1; i <= m; ++i) {
        if (dis[adj[i][0]] == dis[adj[i][1]]) ans.pb(i);
    }
    cout << ans.size() << '\n';
    for (auto i : ans) cout << i << '\n';
}

int main() {
    ios_base::sync_with_stdio(0); cin.tie(NULL);
    int t = 1;
//    cin >> t;
    while (t--) {
        solve();
    }
}

Compilation message

flood.cpp: In function 'void solve()':
flood.cpp:87:37: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   87 |                 for (int k = idx; k < passed.size(); ++k) {
      |                                   ~~^~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 14420 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 14424 KB Output is correct
2 Correct 7 ms 14424 KB Output is correct
3 Correct 8 ms 14420 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 14420 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 14420 KB Output is correct
2 Runtime error 22 ms 29256 KB Execution killed with signal 11
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 22 ms 29088 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 14420 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 7 ms 14420 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 8 ms 14420 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 8 ms 14400 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 23 ms 17236 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Runtime error 84 ms 51108 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 66 ms 26824 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 108 ms 50808 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 120 ms 52300 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -