Submission #304580

# Submission time Handle Problem Language Result Execution time Memory
304580 2020-09-21T14:27:05 Z Akashi Flood (IOI07_flood) C++14
100 / 100
128 ms 16232 KB
#include <bits/stdc++.h>
using namespace std;

const int DIM = 1e5 + 5;
const int NWALL = 2e5 + 5;

///Nord, Vest, Sud, Est
const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, -1, 0, 1};


int n, w;
int x[DIM], y[DIM];
pair <int, int> wh[DIM][4];
int cnt[NWALL];
bool viz[NWALL];

struct elem {
    int x, y, id;
    bool operator < (const elem &aux) const{
        if (x != aux.x) return x < aux.x;
        return y > aux.y;
    }
};

int opus(int dir) {
    if (dir == 0 || dir == 2) dir = 2 - dir;
    else dir = 4 - dir;

    return dir;
}

void dfs(int nod, int dir, int root) {
    if (dir == 4) dir = 0;

    for (int d = dir + 1; d <= dir + 4 ; ++d) {
        int real = d;
        if (real >= 4) real -= 4;

        if (wh[nod][real].first == 0 || viz[wh[nod][real].second]) continue ;
        ++cnt[wh[nod][real].second];

        int aux = wh[nod][real].first;
        wh[nod][real].first = 0;

        if (aux != root)
        dfs(aux, opus(real), root);

        viz[wh[nod][real].second] = 1;
        break ;
    }
}

int main() {
    #ifdef HOME
    freopen("flood.in", "r", stdin);
    freopen("flood.out", "w", stdout);
    #endif // HOME

    scanf("%d", &n);

    vector <elem> point;
    for (int i = 1; i <= n ; ++i) {
        scanf("%d%d", &x[i], &y[i]);
        point.push_back({x[i], y[i], i});
    }

    scanf("%d", &w);
    int a, b;

    for (int i = 1; i <= w ; ++i) {
        scanf("%d%d", &a, &b);
        if (x[a] == x[b]) {
            if (y[a] > y[b]) swap(a, b);

            wh[a][0] = {b, i};
            wh[b][2] = {a, i};
        } else {
            if (x[a] > x[b]) swap(a, b);

            wh[a][3] = {b, i};
            wh[b][1] = {a, i};
        }
    }

    sort (point.begin(), point.end());

    for (auto it : point) {
        for (int dir = 1; dir <= 3 ; ++dir)
            if (wh[it.id][dir].first) dfs(it.id, 1, it.id);
        if (wh[it.id][0].first) dfs(it.id, 1, it.id);
    }

    vector <int> sol;

    for (int i = 1; i <= w ; ++i)
        if (cnt[i] == 2) sol.push_back(i);

    printf("%d\n", sol.size());
    for (auto it : sol) printf("%d\n", it);

    return 0;
}

Compilation message

flood.cpp: In function 'int main()':
flood.cpp:99:14: warning: format '%d' expects argument of type 'int', but argument 2 has type 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wformat=]
   99 |     printf("%d\n", sol.size());
      |             ~^     ~~~~~~~~~~
      |              |             |
      |              int           std::vector<int>::size_type {aka long unsigned int}
      |             %ld
flood.cpp:60:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   60 |     scanf("%d", &n);
      |     ~~~~~^~~~~~~~~~
flood.cpp:64:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   64 |         scanf("%d%d", &x[i], &y[i]);
      |         ~~~~~^~~~~~~~~~~~~~~~~~~~~~
flood.cpp:68:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   68 |     scanf("%d", &w);
      |     ~~~~~^~~~~~~~~~
flood.cpp:72:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   72 |         scanf("%d%d", &a, &b);
      |         ~~~~~^~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 416 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 17 ms 1916 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 76 ms 6636 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 60 ms 5612 KB Output is correct
2 Correct 123 ms 7148 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 108 ms 7020 KB Output is correct
2 Correct 128 ms 10068 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 114 ms 7016 KB Output is correct
2 Correct 113 ms 16232 KB Output is correct