Submission #637005

# Submission time Handle Problem Language Result Execution time Memory
637005 2022-08-31T04:49:13 Z Spade1 Flood (IOI07_flood) C++14
100 / 100
94 ms 28140 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;

//direction: 0 = down, 1 = left, 2 = up, 3 = right
pii pt[N];
pii wall[N][4];
bool w[N][4];
int order[N];
int vis[2*N];
vector<int> pass;
bool out = 0;

void walk(int i, int dir) {
    for (int j = -1; j <= 2; ++j) {
        int cur = (dir+j+4)%4;
        auto [p, n] = wall[i][cur];
        if (p == -1 || vis[n]) continue;
        if (w[i][cur]) {
            out = 1;
            break;
        }
        pass.pb(n);
        w[i][cur] = 1;
        walk(p, cur);
        if (out) break;
    }
}

bool cmp(int a, int b) {
    return pt[a] < pt[b];
}

void solve() {
    int n; cin >> n;
    for (int i = 1; i <= n; ++i) {
        cin >> pt[i].st >> pt[i].nd;
    }
    int m; cin >> m;
    for (int i = 1; i <= n; ++i) for (int j = 0; j < 4; ++j) wall[i][j] = {-1, -1};
    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) wall[a][0] = {b, i}, wall[b][2] = {a, i};
            else wall[a][2] = {b, i}, wall[b][0] = {a, i};
        }
        else {
            if (pt[a].st > pt[b].st) wall[a][1] = {b, i}, wall[b][3] = {a, i};
            else wall[a][3] = {b, i}, wall[b][1] = {a, i};
        }
    }
    for (int i = 1; i <= n; ++i) order[i] = i;
    sort(order+1, order+n+1, cmp);

    for (int i = 1; i <= n; ++i) {
        int j = order[i];
        int idx = pass.size();
        out = 0;
        walk(j, 2);
        for (int k = idx; k < pass.size(); ++k) vis[pass[k]]++;
    }
    int cnt = 0;
    for (int i = 1; i <= m; ++i) cnt += (vis[i]==2);
    cout << cnt << '\n';
    for (int i = 1; i <= m; ++i) if (vis[i] == 2) 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 walk(int, int)':
flood.cpp:26:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   26 |         auto [p, n] = wall[i][cur];
      |              ^
flood.cpp: In function 'void solve()':
flood.cpp:69:29: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   69 |         for (int k = idx; k < pass.size(); ++k) vis[pass[k]]++;
      |                           ~~^~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 328 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 380 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 12 ms 2428 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 45 ms 9472 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 48 ms 5808 KB Output is correct
2 Correct 76 ms 10444 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 74 ms 7756 KB Output is correct
2 Correct 82 ms 9988 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 81 ms 7788 KB Output is correct
2 Correct 94 ms 28140 KB Output is correct