Submission #410606

# Submission time Handle Problem Language Result Execution time Memory
410606 2021-05-23T07:08:21 Z Aldas25 Flood (IOI07_flood) C++14
72 / 100
2000 ms 36720 KB
#pragma GCC optimize("O2")

#include <bits/stdc++.h>

using namespace std;

#define FAST_IO ios_base::sync_with_stdio(0); cin.tie(0)
#define FOR(i, a, b) for(int i = (a); i <= (b); i++)
#define REP(n) FOR(O, 1, (n))
#define pb push_back
#define f first
#define s second
typedef long double ld;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<int, pii> piii;
typedef vector<int> vi;
typedef vector<pii> vii;
typedef vector<ll> vl;
typedef vector<piii> viii;

const int MAXN = 200100, MAXK = 30;
//const ll MOD = 998244353;
const ll INF = 1e17;
const ld PI = asin(1) * 2;

int n;
int x[MAXN], y[MAXN];
int w;
int a[MAXN], b[MAXN];
unordered_set<int> ans;
int deg[MAXN];

set<pair<pii, int>> avPoints;
pii adj[MAXN][4];
bool vis[MAXN][4];
unordered_set<int> curWals;
//vii toEr;

void dfs (int id, int dir) {
    if (vis[id][dir]) return;
    vis[id][dir] = true;

   // cout << "    dfs in id = " << id << " dir = " << dir <<  "  x = " << x[id] << " y = " << y[id] << endl;

    FOR(a, -1, 2) {
        int newDir = (dir + a + 4) % 4;
        if (adj[id][newDir].f == -1) continue;
        int pId = adj[id][newDir].f;
        int wId = adj[id][newDir].s;

        if (!vis[pId][newDir]) {
            if (curWals.count(wId))
                ans.insert(wId);
            else
                curWals.insert(wId);
            dfs(pId, newDir);
        }
        break;
    }


}

int main()
{
    FAST_IO;

    cin >> n;
    FOR(i, 1, n) cin >> x[i] >> y[i];
    cin >> w;
    FOR(i, 1, w) cin >> a[i] >> b[i];

    FOR(i, 1, n) avPoints.insert({{x[i], y[i]}, i});
    FOR(i, 1, n) FOR(d, 0, 3) adj[i][d] = {-1, -1};

    FOR(i, 1, w) {
        if (x[a[i]] > x[b[i]] || y[a[i]] > y[b[i]]) swap(a[i], b[i]);
        if (y[a[i]] == y[b[i]]) {
            adj[a[i]][1] = {b[i], i};
            adj[b[i]][3] = {a[i], i};
        } else {
            adj[a[i]][0] = {b[i], i};
            adj[b[i]][2] = {a[i], i};
        }

        deg[a[i]]++;
        deg[b[i]]++;
    }

    while ((int)avPoints.size() > 0) {
        auto p = *(avPoints.begin());
        curWals.clear();
        int id = p.s;
        //toEr.clear();

       // cout << " starting walk from id = " << id << " x = " << x[id] << " y = " << y[id] << endl;

        int stDir = 0;
        while (vis[id][stDir]) {stDir++;}
        dfs (id, stDir);

        for (auto wall : curWals) {
            int i = wall;
            if (y[a[i]] == y[b[i]]) {
                adj[a[i]][1] = {-1, -1};
                adj[b[i]][3] = {-1, -1};
            } else {
                adj[a[i]][0] = {-1, -1};
                adj[b[i]][2] = {-1, -1};
            }
            deg[a[i]]--;
            deg[b[i]]--;

            int id;
            id = a[i];
            if (deg[id] == 0 && avPoints.count({{x[id], y[id]}, id}))
                avPoints.erase({{x[id], y[id]}, id});
            id = b[i];
            if (deg[id] == 0 && avPoints.count({{x[id], y[id]}, id}))
                avPoints.erase({{x[id], y[id]}, id});
        }
    }

    cout << (int)ans.size() << "\n";
    for (int wall : ans) cout << wall << "\n";

    return 0;
}


# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 460 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 2076 ms 332 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 2 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 2076 ms 3776 KB Time limit exceeded
# Verdict Execution time Memory Grader output
1 Correct 142 ms 15632 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 89 ms 13164 KB Output is correct
2 Correct 248 ms 17168 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 220 ms 16500 KB Output is correct
2 Correct 208 ms 16628 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 246 ms 16908 KB Output is correct
2 Runtime error 203 ms 36720 KB Memory limit exceeded