Submission #484313

# Submission time Handle Problem Language Result Execution time Memory
484313 2021-11-02T23:28:54 Z MohamedFaresNebili Cop and Robber (BOI14_coprobber) C++14
Compilation error
0 ms 0 KB
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#pragma GCC optimize ("Ofast")
#pragma GCC target ("avx2")
#include "coprobber.h"
 
        using namespace std;
        using namespace __gnu_pbds;
 
        using ll  = long long;
        using ld  = long double;
        using ii  = pair<ll, ll>;
        using ull = unsigned long long;
 
        using vl  = vector<long long>;
 
        #define mp make_pair
        #define pb push_back
        #define pp pop_back
        #define ff first
        #define ss second
        #define lb lower_bound
        #define ub upper_bound
        #define all(x) (x).begin() , (x).end()
        #define vi vector<int>
 
        const int N = 2*100005;
        const long long MOD = 1000000007;
        const long double EPS = 0.000000001;
        const double PI = 3.14159265358979323846;
        const long long INF = 10000000000000000;
 
        long long gcd(int a, int b) { return (b==0?a:gcd(b, a%b)); }
        long long lcm(int a, int b) { return  a*(b/gcd(a, b)); }
        long long fact(int a) { return (a==1?1:a*fact(a-1)); }
 
        template<class T> using Tree = tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;
 
        #define MAX_N 500
        vector<int>adj[MAX_N];
 
        int police = 0, r, c; bool grid = 0;

        bitset<524>prime;
        void init() {
            prime[1] = prime[0] = 1;
            for(int l = 2; l <= 500; l++) {
                for(int i = 2; i * l <= 500; i++)
                    prime[l*i] = 1;
            }
        }
        bool grid(int N) {
            if(!prime[N]) return 0;
            int a = 0, b = 0, c = 0;
            for(int l = 0; l < N; l++) {
                int sz = (int)adj[l].size();
                a+=(sz==2);
                b+=(sz==3);
                c+=(sz==4);
            }
            if(a!=4||a+b+c!=N) return 0;
            bool ok = 0;
            for(int l = 2; l * l <= N; l++) {
                if(N % l) continue;
                int curr = l*2 + (N/l)*2 - 4;
                ok |= ((curr == a + b) && (c == N - curr));
            }
            return ok;
        }
 
        int start(int N, bool A[MAX_N][MAX_N])
        {
            for(int l = 0; l < N; l++) {
                for(int i=0; i < N; i++) {
                    if(A[l][i]) adj[l].pb(i);
                }
            }
            c = adj[0][1];
            r = N/c;
            grid = isgrid(A);
            return 0;
        }
 
        const int nx[4] = {0, 0, 1, -1}, ny[4] = {1, -1, 0, 0};
        int dist(int x, int y, int a, int b) { return abs(x-a)+abs(y-b); }
 
        int nextMove(int R)
        {
            if(grid) {
                int r1 = police / c, r2 = R / c;
                int c1 = police % c, c2 = R % c;
                int a = abs(r1 - r2), b = abs(c1 - c2);
                if(a < b) {
                    int curr = 1e9, xx, yy;
                    for(int l = 0; l < 2; l++) {
                        int x = r1 + nx[l], y = c1 + ny[l];
                        int d = dist(x, y, r2, c1);
                        if(d < curr) xx = x, yy = y, curr = d;
                    }
                    return police = xx * c + yy;
                }
                else if(a > b) {
                    int curr = 1e9, xx, yy;
                    for(int l = 2; l < 4; l++) {
                        int x = r1 + nx[l], y = c1 + ny[l];
                        int d = dist(x, y, r2, c1);
                        if(d < curr) xx = x, yy = y, curr = d;
                    }
                    return police = xx * c + yy;
                }
                else if(a == b) return police;
            }
            else {
                for(auto u:adj[Police]) {
                    if(u==R||dfs(u, Police, R)) {
                        return Police = u;
                    }
                }
            }
        }

Compilation message

coprobber.cpp:52:24: error: 'bool grid(int)' redeclared as different kind of entity
   52 |         bool grid(int N) {
      |                        ^
coprobber.cpp:42:36: note: previous declaration 'bool grid'
   42 |         int police = 0, r, c; bool grid = 0;
      |                                    ^~~~
coprobber.cpp: In function 'int start(int, bool (*)[500])':
coprobber.cpp:80:20: error: 'isgrid' was not declared in this scope; did you mean 'grid'?
   80 |             grid = isgrid(A);
      |                    ^~~~~~
      |                    grid
coprobber.cpp: In function 'int nextMove(int)':
coprobber.cpp:114:32: error: 'Police' was not declared in this scope; did you mean 'police'?
  114 |                 for(auto u:adj[Police]) {
      |                                ^~~~~~
      |                                police
coprobber.cpp:115:30: error: 'dfs' was not declared in this scope; did you mean 'ffs'?
  115 |                     if(u==R||dfs(u, Police, R)) {
      |                              ^~~
      |                              ffs