Submission #677489

# Submission time Handle Problem Language Result Execution time Memory
677489 2023-01-03T13:08:02 Z dooompy Cop and Robber (BOI14_coprobber) C++17
100 / 100
668 ms 10512 KB
#include "bits/stdc++.h"
#include "coprobber.h"


using namespace std;

void abc() {cout << endl;}
template <typename T, typename ...U> void abc(T a, U ...b) {
    cout << a << ' ', abc(b...);
}
template <typename T> void printv(T l, T r) {
    while (l != r) cout << *l << " \n"[++l == r];
}
template <typename A, typename B> istream& operator >> (istream& o, pair<A, B> &a) {
    return o >> a.first >> a.second;
}
template <typename A, typename B> ostream& operator << (ostream& o, pair<A, B> a) {
    return o << '(' << a.first << ", " << a.second << ')';
}
template <typename T> ostream& operator << (ostream& o, vector<T> a) {
    bool is = false;
    for (T i : a) {o << (is ? ' ' : '{'), is = true, o << i;}
    return o << '}';
}

#ifdef local
#define test(args...) abc("[" + string(#args) + "]", args)
#else
#define test(args...) void(0)
#endif

using ll = long long;

struct state {
    int cop, robber, move;
};

vector<int> adj[505];
int dp[505][505][2];
int moves[505][505][2]; // 0 - cops turn, 1 - robbers turn
int ct[505][505];

int pos = 0;

int start(int n, bool a[500][500]) {
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
            if (a[i][j]) {
                adj[i].push_back(j);
            }
        }
    }

    queue<state> states;

    for (int i = 0; i < n; i++) {
        states.push({i, i, 0});
        states.push({i, i, 1});

        dp[i][i][0] = dp[i][i][1] = true;
        moves[i][i][0] = moves[i][i][1] = i;
    }

    while (!states.empty()) {
        auto [cop, robber, move] = states.front(); states.pop();

        if (move == 0) {
            // robber just moved to this square

            for (auto nxt : adj[robber]) {
                ct[cop][nxt]++;

                if (ct[cop][nxt] == adj[nxt].size()) {
                    // forced to move
                    dp[cop][nxt][1] = 1;
                    states.push({cop, nxt, 1});
                }
            }
        } else {
            for (auto nxt : adj[cop]) {
                if (dp[nxt][robber][0] == 1) continue;
                dp[nxt][robber][0] = 1;
                moves[nxt][robber][0] = cop;
                states.push({nxt, robber, 0});
            }

            if (dp[cop][robber][0] != 1) {
                dp[cop][robber][0] = 1;
                moves[cop][robber][0] = cop;
                states.push({cop, robber, 0});
            }
        }
    }

    int ok = 0;
    for (int i = 0; i < n; i++) {
        if (dp[0][i][0] != 1) {
            ok = -1;
            break;
        }
    }

    return ok;
}

int nextMove(int r) {
    return pos = moves[pos][r][0];
}
 

Compilation message

coprobber.cpp: In function 'int start(int, bool (*)[500])':
coprobber.cpp:73:34: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   73 |                 if (ct[cop][nxt] == adj[nxt].size()) {
      |                     ~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 50 ms 6624 KB Output is correct
5 Correct 16 ms 3280 KB Output is correct
6 Correct 57 ms 6952 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 336 KB Output is correct
2 Correct 1 ms 464 KB Output is correct
3 Correct 50 ms 6616 KB Output is correct
4 Correct 71 ms 6640 KB Output is correct
5 Correct 52 ms 6584 KB Output is correct
6 Correct 49 ms 6576 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 336 KB Output is correct
2 Correct 0 ms 336 KB Output is correct
3 Correct 0 ms 416 KB Output is correct
4 Correct 0 ms 336 KB Output is correct
5 Correct 1 ms 464 KB Output is correct
6 Correct 0 ms 336 KB Output is correct
7 Correct 1 ms 336 KB Output is correct
8 Correct 1 ms 336 KB Output is correct
9 Correct 1 ms 464 KB Output is correct
10 Correct 3 ms 1360 KB Output is correct
11 Correct 3 ms 1360 KB Output is correct
12 Correct 1 ms 592 KB Output is correct
13 Correct 1 ms 1104 KB Output is correct
14 Correct 2 ms 1360 KB Output is correct
15 Correct 1 ms 848 KB Output is correct
16 Correct 2 ms 848 KB Output is correct
17 Correct 6 ms 1588 KB Output is correct
18 Correct 2 ms 1360 KB Output is correct
19 Correct 0 ms 336 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 50 ms 6624 KB Output is correct
5 Correct 16 ms 3280 KB Output is correct
6 Correct 57 ms 6952 KB Output is correct
7 Correct 0 ms 336 KB Output is correct
8 Correct 1 ms 464 KB Output is correct
9 Correct 50 ms 6616 KB Output is correct
10 Correct 71 ms 6640 KB Output is correct
11 Correct 52 ms 6584 KB Output is correct
12 Correct 49 ms 6576 KB Output is correct
13 Correct 0 ms 336 KB Output is correct
14 Correct 0 ms 336 KB Output is correct
15 Correct 0 ms 416 KB Output is correct
16 Correct 0 ms 336 KB Output is correct
17 Correct 1 ms 464 KB Output is correct
18 Correct 0 ms 336 KB Output is correct
19 Correct 1 ms 336 KB Output is correct
20 Correct 1 ms 336 KB Output is correct
21 Correct 1 ms 464 KB Output is correct
22 Correct 3 ms 1360 KB Output is correct
23 Correct 3 ms 1360 KB Output is correct
24 Correct 1 ms 592 KB Output is correct
25 Correct 1 ms 1104 KB Output is correct
26 Correct 2 ms 1360 KB Output is correct
27 Correct 1 ms 848 KB Output is correct
28 Correct 2 ms 848 KB Output is correct
29 Correct 6 ms 1588 KB Output is correct
30 Correct 2 ms 1360 KB Output is correct
31 Correct 0 ms 336 KB Output is correct
32 Correct 1 ms 336 KB Output is correct
33 Correct 0 ms 336 KB Output is correct
34 Correct 0 ms 320 KB Output is correct
35 Correct 49 ms 6628 KB Output is correct
36 Correct 14 ms 3392 KB Output is correct
37 Correct 66 ms 6888 KB Output is correct
38 Correct 1 ms 276 KB Output is correct
39 Correct 1 ms 476 KB Output is correct
40 Correct 51 ms 6660 KB Output is correct
41 Correct 49 ms 6668 KB Output is correct
42 Correct 51 ms 6508 KB Output is correct
43 Correct 52 ms 6496 KB Output is correct
44 Correct 0 ms 336 KB Output is correct
45 Correct 1 ms 336 KB Output is correct
46 Correct 1 ms 336 KB Output is correct
47 Correct 0 ms 464 KB Output is correct
48 Correct 2 ms 1360 KB Output is correct
49 Correct 3 ms 1360 KB Output is correct
50 Correct 1 ms 592 KB Output is correct
51 Correct 1 ms 1104 KB Output is correct
52 Correct 3 ms 1360 KB Output is correct
53 Correct 1 ms 976 KB Output is correct
54 Correct 1 ms 848 KB Output is correct
55 Correct 5 ms 1652 KB Output is correct
56 Correct 2 ms 1408 KB Output is correct
57 Correct 5 ms 2384 KB Output is correct
58 Correct 15 ms 4424 KB Output is correct
59 Correct 21 ms 5576 KB Output is correct
60 Correct 668 ms 10512 KB Output is correct
61 Correct 73 ms 6348 KB Output is correct
62 Correct 65 ms 6836 KB Output is correct
63 Correct 463 ms 9244 KB Output is correct
64 Correct 41 ms 6240 KB Output is correct
65 Correct 492 ms 10328 KB Output is correct
66 Correct 62 ms 7104 KB Output is correct
67 Correct 244 ms 8712 KB Output is correct
68 Correct 87 ms 6060 KB Output is correct
69 Correct 0 ms 336 KB Output is correct