Submission #477254

# Submission time Handle Problem Language Result Execution time Memory
477254 2021-10-01T12:25:50 Z Lobo Cop and Robber (BOI14_coprobber) C++17
0 / 100
1 ms 328 KB
#include <iostream>
#include <bits/stdc++.h>
 
using namespace std;

const long long INFll = (long long) 1e18 + 10;
const int INFii = (int) 1e9 + 10;
typedef long long ll;
typedef int ii;
typedef long double dbl;
#define endl '\n'
#define sc second
#define fr first
#define mp make_pair
#define pb push_back
#define all(x) x.begin(), x.end()
#define MAX_N 500

#define maxn 510

// modify the following functions
// you can define global variables and functions

ii n, act, d1[maxn], d2[maxn][maxn], cic[maxn];
vector<ii> g[maxn];


void bfs(ii p1, ii p2) {
    for(ii i = 0; i < n; i++) {
        d1[i] = -1; //?
    }

    d1[p1] = 0;

    queue<ii> q;
    q.push(p1);

    while(q.size()) {
        ii u = q.front();
        q.pop();

        for(auto v : g[u]) {
            if(d1[v] == -1 && !(u == p1 && v == p2)) {
                d1[v] = d1[u]+1;
                q.push(v);
            }
        }
    }
}
 


int start(int N, bool A[MAX_N][MAX_N]) {
    n = N;
    for(ii i = 0; i < N; i++) {
        for(ii j = 0; j < N; j++) {
            d2[i][j] = INFii;
            if(A[i][j]) {
                //cout << i << " " << j << endl;
                d2[i][j] = 1;
                g[i].pb(j);
            }
        }
        d2[i][i] = 0;
    }

    for(ii i = 0; i < N; i++) {
        for(ii j = 0; j < N; j++) {
            for(ii k = 0; k < N; k++) {
                d2[j][k] = min(d2[j][k],d2[j][i]+d2[i][k]);
            }
        }
    }

    for(ii i = 0; i < N; i++) {
        for(ii j = 0; j < N; j++) {
            //cout << i << " " << j << " = " << d2[i][j] << endl; 
       }
    }

    for(ii i = 0; i < N; i++) {
        for(auto j : g[i]) {
            bfs(i,j);

            if(d1[j] >= 3) cic[j] = 1;
            //cout << i << " " << j << " = " << d1[j] << endl;
        }
    }


    for(ii i = 0; i < N; i++) {
        bool ok = true;
        for(ii j = 0; j < N; j++) {
            for(ii k = 0; k < N; k++) {
                if(d2[j][k] < d2[i][k]-1 && cic[k] == 1) {
                    ok = false;
                }
            }
        }

        if(ok) {
            act = i;
            return i;
        }
    }

    return -1;

}

int nextMove(int R) {
    return 0;
}

# Verdict Execution time Memory Grader output
1 Correct 1 ms 328 KB Output is correct
2 Correct 0 ms 328 KB Output is correct
3 Incorrect 0 ms 328 KB the situation repeated
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 328 KB Cop can catch the robber, but start() returned -1
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 328 KB Output is correct
2 Correct 0 ms 328 KB Output is correct
3 Incorrect 1 ms 328 KB the situation repeated
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 328 KB Output is correct
2 Correct 0 ms 328 KB Output is correct
3 Incorrect 0 ms 328 KB the situation repeated
4 Halted 0 ms 0 KB -