Submission #484363

# Submission time Handle Problem Language Result Execution time Memory
484363 2021-11-03T00:19:35 Z AmirElarbi Cop and Robber (BOI14_coprobber) C++14
Compilation error
0 ms 0 KB
#include <bits/stdc++.h>
#include "coprobber.h"
using namespace std;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef long long ll;
typedef pair<ll,ll> pll;
typedef tuple<int,int,int> ti;
typedef unsigned long long ull;
typedef long double ld;
typedef vector<ll> vll;
typedef pair<ld,ld> pld;
#define pb push_back
#define popb pop_back()
#define pf push_front
#define popf pop_front
#define ff first
#define ss second
#define MOD (ll)(1000000007)
#define INF (ll) (1e18)
#define all(v) (v).begin(),(v).end()
const int nx[8] = {0, 0, 1, -1,1,1,-1,-1}, ny[8] = {1, -1, 0, 0,1,-1,1,-1}; //East, West, South, North+
ll gcd(ll a , ll b) {return b ? gcd(b , a % b) : a ;}
ll lcm(ll a, ll b){return (a / gcd(a, b)) * b;}
////////////******SOLUTION******\\\\\\\\\\\

const int MAX_NN = 501;
int n;
vi adj[MAX_NN];
int state[MAX_NN];
int pos;
int dp[MAX_NN][MAX_NN][2];
int f(int i, int j, int turn)
{
    if(dp[i][j][turn] != -1)
       return dp[i][j][turn];
    if(turn == 0) // thief playing
    {
        if(i == j) // cop went to thief's position
            return dp[i][j][turn] = -2;
        for(auto e: adj[i])
        {
            if(e == j)
                continue;
            if(f(e,j,1-turn) == -2)
                return dp[i][j][turn] = e;
        }
        return dp[i][j][turn] = -2;
    }
    else
    {
        if(i == j)
            return dp[i][j][turn] = j;
        for(auto e: adj[j])
        {
            if(e == i)
                return dp[i][j][turn] = e;
            if(f(i,e,1-turn) == -2)
                return dp[i][j][turn] = e;
        }
        if(f(i,j,1-turn) == -2)
            return dp[i][j][turn] = j;
        return dp[i][j][turn] = -2;
    }
}
int nextMove(int r)
{
     pos = f(r, pos, 1); // update pos to the position we're going to
     return pos;
}
int start(int N, bool A[MAX_NN][MAX_NN])
{
    n = N;
    memset(dp,-1,sizeof(dp));
    for(int i = 0; i <n-1; i++)
    {
        for(int j = i + 1; j <n; j ++)
        {
            if(A[i][j])
            {
                adj[i].pb(j);
                adj[j].pb(i);
            }
        }
    }
    memset(state,0,sizeof(state));
    for(int j = 0; j <n; j ++)
    {
        bool flag = true;
        for(int i =0; i <n; i ++)
        {
           flag = flag & (f(i,j,0) ==
   -2);
        }
        state[j] = flag;
    }
    int u = -1;
    for(int j = 0; j <n; j ++)
    {
        u = state[j]? j: u;
    }
    if(u == -1) return -1;
    return pos = u;
}

    int main() {
        int N;
        cin >> N;
        bool A[MAX_N][MAX_N];
        for (int i = 0; i < N; i++) {
            for (int j = 0; j < N; j++) {
                cin >> A[i][j];
            }
        }
        int P = start(N,A);
        cout << P << endl;
        int R;
        cin >> R;
        while (true) {
            if (P == R) break;
            P = nextMove(R);
            cout << P << endl;
            if (P == R) break;
            cin >> R;
    }
/* 6 3 2
2 5 1 5 1 3 6 3 6 4
3 2 3 4
2 1 6
3 1 6 4
*/
/*
6 3 3
1 3
2 3
3 4
6 4
4 5
2 1 3
2 6 3
2 3 2
*/

Compilation message

coprobber.cpp:25:1: warning: multi-line comment [-Wcomment]
   25 | ////////////******SOLUTION******\\\\\\\\\\\
      | ^
coprobber.cpp: In function 'int main()':
coprobber.cpp:125:5: error: expected '}' at end of input
  125 |     }
      |     ^
coprobber.cpp:106:16: note: to match this '{'
  106 |     int main() {
      |                ^