제출 #107615

#제출 시각아이디문제언어결과실행 시간메모리
107615dfistric경찰관과 강도 (BOI14_coprobber)C++14
30 / 100
51 ms1912 KiB
#include "coprobber.h"
#include <bits/stdc++.h>

#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define FORd(i, a, b) for (int i = (a); i >= (b); i--)
#define REP(i, n) FOR(i, 0, n)
#define ll long long

using namespace std;

int strategy;
int n;
vector <int> ve[MAX_N];
int D[MAX_N], F[MAX_N];
int disc = -1;
int P, W, H;

void rek(int x, int p) {
    D[x] = ++disc;

    for (int y : ve[x]) {
        if (y == p) continue;
        rek(y, x);
    }

    F[x] = disc;
    return; 
}

int start(int N, bool A[MAX_N][MAX_N]) {
    n = N;
    int e = 0;

    REP(i, n) {
        REP(j, n) {
            if (A[i][j]) ve[i].push_back(j), e++;
        }
    }
    e /= 2;

    if (e == n - 1) {
        rek(0, 0);
        strategy = 0, P = 0;
        return 0;
    }

    W = 1, H = 1;
    while (A[W - 1][W] == 1) W++;
    H = n / W;

    assert(H * W == n);

    strategy = 1, P = 0;

    return 0;
}

int nextMove(int R) {

    if (strategy == 0) {
        for (int x : ve[P]) {
            if (D[x] < D[P]) continue;
        
            if (D[x] <= D[R] && F[R] <= F[x]) {
                P = x;
                return P;
            }
        }
        assert(0);
    } else if (strategy == 1) {
        if (abs((R % W) - (P % W)) == 1 && abs((R / W) - (P / W)) == 1) return P;


        if (R % W == P % W) {
            if (R > P) P += W;
            else       P -= W;

            return P;
        } else if (abs((R % W) - (P % W)) == 1) {
            if (R / W == P / W) {
                if (R > P) P++;
                else       P--;

                return P;
            } else {
                if (R > P) P += W;
                else       P -= W;

                return P;
            }
        } else {
            if (R % W > P % W) P++;
            else               P--;

            return P;
        }
    } else {
        assert(0);
    }

    return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...