Submission #240742

# Submission time Handle Problem Language Result Execution time Memory
240742 2020-06-21T04:20:20 Z thecodingwizard Flood (IOI07_flood) C++11
Compilation error
0 ms 0 KB
#include <bits/stdc++.h>

using namespace std;

#define ii pair<int, int>
#define f first
#define s second
#define ll long long

ii A[100000];
struct Wall {
    int a, b;
    int idx;

    bool operator<(const Wall &other) const {
        int x = min(A[a].f, A[b].f);
        int y = min(A[other.a].f, A[other.b].f);
        int X = max(A[a].f, A[b].f);
        int Y = max(A[other.a].f, A[other.b].f);
        if (x==y&&X==Y) {
            return idx < other.idx;
        }
        return x==y?X<Y:x<y;
    }
};

int n;
vector<int> graph[100000];
vector<Wall> walls;
bool swcmp(int a, int b) { return walls[a] < walls[b]; }
set<int, decltype(swcmp)> sortedWalls;
bitset<200000> vis[2];
bitset<200000> done;
vector<int> justDone;

ll cross(int a, int b, int c) {
    int w = A[b].f-A[a].f, x = A[b].s - A[a].s, y = A[c].f - A[b].f, z = A[c].s - A[b].s;
    return (ll)w*z-(ll)x*y;
}

bool turnRight(int a, int b, int c) {
    return cross(a, b, c) < 0;
}
bool turnLeft(int a, int b, int c) {
    return cross(a, b, c) > 0;
}
bool goForward(int a, int b, int c) {
    int w = A[b].f-A[a].f, x = A[b].s - A[a].s, y = A[c].f - A[b].f, z = A[c].s - A[b].s;
    return (w==y&&(x<0)==(z<0))||(x==z&&(w<0)==(y<0));
    //return (A[a].f==A[b].f&&A[b].f==A[c].f&&(A[a].s<A[b].s&&A[b].s<A[c].s||A[a].s>A[b].s&&A[b].s>A[c].s))||(A[a].s==A[b].s&&A[b].s==A[c].s&&(A[a].f<A[b].f&&A[b].f<A[c].f||A[a].f>A[b].f&&A[b].f>A[c].f));
}

bool goBack(int a, int b, int c) {
    int w = A[b].f-A[a].f, x = A[b].s - A[a].s, y = A[c].f - A[b].f, z = A[c].s - A[b].s;
    return (w==y&&(x<0)!=(z<0))||(x==z&&(w<0)!=(y<0));
    //return (A[a].f==A[b].f&&A[b].f==A[c].f&&(A[a].s<A[b].s&&A[b].s<A[c].s||A[a].s>A[b].s&&A[b].s>A[c].s))||(A[a].s==A[b].s&&A[b].s==A[c].s&&(A[a].f<A[b].f&&A[b].f<A[c].f||A[a].f>A[b].f&&A[b].f>A[c].f));
}

void go(int u, int dir) {
    //cout << "go: " << u << " " << dir << endl;
    if (vis[dir][u]) return;
    vis[dir][u] = true;
    justDone.push_back(u);
    Wall w = walls[u];
    sortedWalls.erase(u);

    int prvNode = dir == 0 ? w.b : w.a;
    int node = dir == 0 ? w.a : w.b;

    // left
    for (int wID : graph[node]) {
        int nxtNode = walls[wID].a == node ? walls[wID].b : walls[wID].a;
        int nxtDir = walls[wID].a == nxtNode ? 0 : 1;
        if (!done[wID] && turnLeft(prvNode, node, nxtNode)) {
            //cout << "left" << endl;
            return go(wID, nxtDir);
        }
    }

    // forward
    for (int wID : graph[node]) {
        int nxtNode = walls[wID].a == node ? walls[wID].b : walls[wID].a;
        int nxtDir = walls[wID].a == nxtNode ? 0 : 1;
        if (!done[wID] && goForward(prvNode, node, nxtNode)) {
            //cout << "forward" << endl;
            return go(wID, nxtDir);
        }
    }
    
    // right
    for (int wID : graph[node]) {
        int nxtNode = walls[wID].a == node ? walls[wID].b : walls[wID].a;
        int nxtDir = walls[wID].a == nxtNode ? 0 : 1;
        if (!done[wID] && turnRight(prvNode, node, nxtNode)) {
            //cout << "right" << endl;
            return go(wID, nxtDir);
        }
    }
    
    // back
    for (int wID : graph[node]) {
        int nxtNode = walls[wID].a == node ? walls[wID].b : walls[wID].a;
        int nxtDir = walls[wID].a == nxtNode ? 0 : 1;
        if (!done[wID]) {
            assert(goBack(prvNode, node, nxtNode));
            //cout << "back" << endl;
            return go(wID, nxtDir);
        }
    }
}

int main() {
    int n; cin >> n;
    for (int i = 0; i < n; i++) cin >> A[i].f >> A[i].s;
    int w; cin >> w;
    for (int i = 0; i < w; i++) {
        int a, b; cin >> a >> b; --a; --b;
        sortedWalls.insert({a,b,i});
        walls.push_back({a,b,i});
        graph[a].push_back(i);
        graph[b].push_back(i);
        vis[0][i] = vis[1][i] = false;
        done[i] = false;
    }

    while (!sortedWalls.empty()) {
        //cout << "=== new go ===" << endl;
        int u = *sortedWalls.begin();
        int x = A[walls[u].a].f - A[walls[u].b].f, y = A[walls[u].b].s - A[walls[u].a].s;
        if (x<0||y<0) {
            go(*sortedWalls.begin());
        } else {
            go(*sortedWalls.begin());
        }
        
        for (int x : justDone) done[x] = true;
        justDone.clear();
    }

    vector<int> ans;
    for (int i = 0; i < w; i++) {
        if (vis[0][i] && vis[1][i]) {
            ans.push_back(i);
        }
    }
    cout << ans.size() << endl;
    for (int i = 0; i < ans.size(); i++) {
        cout << ans[i]+1 << endl;
    }

    return 0;
}

Compilation message

In file included from /usr/include/c++/7/map:60:0,
                 from /usr/include/x86_64-linux-gnu/c++/7/bits/stdc++.h:81,
                 from flood.cpp:1:
/usr/include/c++/7/bits/stl_tree.h: In instantiation of 'struct std::_Rb_tree_key_compare<bool(int, int)>':
/usr/include/c++/7/bits/stl_tree.h:677:16:   required from 'struct std::_Rb_tree<int, int, std::_Identity<int>, bool(int, int), std::allocator<int> >::_Rb_tree_impl<bool(int, int), false>'
/usr/include/c++/7/bits/stl_tree.h:708:31:   required from 'class std::_Rb_tree<int, int, std::_Identity<int>, bool(int, int), std::allocator<int> >'
/usr/include/c++/7/bits/stl_set.h:123:17:   required from 'class std::set<int, bool(int, int)>'
flood.cpp:31:27:   required from here
/usr/include/c++/7/bits/stl_tree.h:144:21: error: field 'std::_Rb_tree_key_compare<bool(int, int)>::_M_key_compare' invalidly declared function type
       _Key_compare  _M_key_compare;
                     ^~~~~~~~~~~~~~
/usr/include/c++/7/bits/stl_tree.h: In instantiation of 'class std::_Rb_tree<int, int, std::_Identity<int>, bool(int, int), std::allocator<int> >':
/usr/include/c++/7/bits/stl_set.h:123:17:   required from 'class std::set<int, bool(int, int)>'
flood.cpp:31:27:   required from here
/usr/include/c++/7/bits/stl_tree.h:956:7: error: function returning a function
       key_comp() const
       ^~~~~~~~
In file included from /usr/include/c++/7/set:61:0,
                 from /usr/include/x86_64-linux-gnu/c++/7/bits/stdc++.h:87,
                 from flood.cpp:1:
/usr/include/c++/7/bits/stl_set.h: In instantiation of 'class std::set<int, bool(int, int)>':
flood.cpp:31:27:   required from here
/usr/include/c++/7/bits/stl_set.h:317:7: error: function returning a function
       key_comp() const
       ^~~~~~~~
/usr/include/c++/7/bits/stl_set.h:321:7: error: function returning a function
       value_comp() const
       ^~~~~~~~~~
flood.cpp: In function 'int main()':
flood.cpp:131:36: error: too few arguments to function 'void go(int, int)'
             go(*sortedWalls.begin());
                                    ^
flood.cpp:59:6: note: declared here
 void go(int u, int dir) {
      ^~
flood.cpp:133:36: error: too few arguments to function 'void go(int, int)'
             go(*sortedWalls.begin());
                                    ^
flood.cpp:59:6: note: declared here
 void go(int u, int dir) {
      ^~
flood.cpp:147:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (int i = 0; i < ans.size(); i++) {
                     ~~^~~~~~~~~~~~