Submission #304576

# Submission time Handle Problem Language Result Execution time Memory
304576 2020-09-21T14:21:28 Z Akashi Flood (IOI07_flood) C++14
20 / 100
144 ms 10596 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 a, b, id;
    bool operator < (const elem &aux) const{
        if (x[a] != x[aux.a]) return x[a] < x[aux.a];
        if (y[a] != y[aux.a]) return y[a] > y[aux.a];
        if (x[b] != x[aux.b]) return x[b] < x[aux.b];
        return y[b] >  y[aux.b];
    }
};

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);

    for (int i = 1; i <= n ; ++i)
        scanf("%d%d", &x[i], &y[i]);

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

    vector <elem> wall;
    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};
        }

        wall.push_back({b, a, i});
    }

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

    for (int i = 0; i < w ; ++i) {
        if (cnt[wall[i].id]) continue ;

        dfs(wall[i].a, 1, wall[i].a);
    }

    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:101:14: warning: format '%d' expects argument of type 'int', but argument 2 has type 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wformat=]
  101 |     printf("%d\n", sol.size());
      |             ~^     ~~~~~~~~~~
      |              |             |
      |              int           std::vector<int>::size_type {aka long unsigned int}
      |             %ld
flood.cpp:62:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   62 |     scanf("%d", &n);
      |     ~~~~~^~~~~~~~~~
flood.cpp:65:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   65 |         scanf("%d%d", &x[i], &y[i]);
      |         ~~~~~^~~~~~~~~~~~~~~~~~~~~~
flood.cpp:67:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   67 |     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 0 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 384 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 384 KB Output is correct
2 Incorrect 1 ms 384 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 384 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 384 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 384 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Incorrect 1 ms 384 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 384 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 21 ms 1788 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Incorrect 60 ms 6632 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Correct 65 ms 5484 KB Output is correct
2 Incorrect 144 ms 10596 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Incorrect 115 ms 7276 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 137 ms 7540 KB Output isn't correct
2 Halted 0 ms 0 KB -