제출 #476555

#제출 시각아이디문제언어결과실행 시간메모리
476555SamAndCop and Robber (BOI14_coprobber)C++17
100 / 100
1146 ms7156 KiB
#include "coprobber.h"
#include <iostream>
#include <set>
#include <cstring>
#include <cassert>
#include <vector>
#include <queue>

using namespace std;

#define m_p make_pair
#define fi first
#define se second

int cnt[MAX_N][MAX_N];

bool c[MAX_N][MAX_N][2];
int p[MAX_N][MAX_N];

int start(int n, bool a[MAX_N][MAX_N]) {

    for (int i = 0; i < n; ++i)
    {
        for (int j = 0; j < n; ++j)
        {
            for (int k = 0; k < n; ++k)
            {
                if (a[j][k])
                {
                    ++cnt[i][j];
                }
            }
        }
    }

    queue<pair<pair<int, int>, bool> > q;

    for (int i = 0; i < n; ++i)
    {
        c[i][i][0] = true;
        q.push(m_p(m_p(i, i), 0));
        c[i][i][1] = true;
        q.push(m_p(m_p(i, i), 1));
    }

    int qq = 0;
    while (!q.empty())
    {
        int u = q.front().fi.fi;
        int r = q.front().fi.se;
        bool z = q.front().se;
        q.pop();
        ++qq;

        if (!z)
        {
            for (int h = 0; h < n; ++h)
            {
                if (h == u || a[u][h])
                {
                    if (!c[h][r][1])
                    {
                        p[h][r] = u;
                        c[h][r][1] = true;
                        q.push(m_p(m_p(h, r), 1));
                    }
                }
            }
        }
        else
        {
            for (int h = 0; h < n; ++h)
            {
                if (a[r][h])
                {
                    --cnt[u][h];
                    if (!c[u][h][0] && cnt[u][h] == 0)
                    {
                        c[u][h][0] = true;
                        q.push(m_p(m_p(u, h), 0));
                    }
                }
            }
        }
    }

    if (qq == 2 * n * n)
        return 0;
    return -1;
}

int u;
int nextMove(int r) {
    u = p[u][r];
    return u;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...