1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#include <bits/stdc++.h>
#include "osalib.h"
using namespace std;

typedef long long LL;
typedef long double LD;
typedef pair < int, int > PII;
typedef pair < LL, LL > PLL;
typedef pair < LD, LD > PDD;

#define _upgrade ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define all(x) (x).begin(), (x).end()
#define sz(x) (int)(x).size()

// ********************** CODE ********************** //

const int N = 1e3 + 7;

int ile = 0;
vector < PII > pos;
int n1, m1;
char s[N][N];

void NowaWyspa(int n, int m, char **board)
{
    n1 = n, m1 = m;
    for(int i = 1; i <= n; i++)
        for(int j = 1; j <= m; j++)
        {
            s[i][j] = board[i - 1][j - 1];
            if(s[i][j] == 'K')
            {
                ile++;
                pos.push_back({i, j});
            }
        }
}

int p[] = {1, 0, 0, 1, -1, 0, 0, -1};
bool vis[N][N];
int cnt;

void dfs(int x, int y)
{
    vis[x][y] = 1;
    if(s[x][y] == 'K')
        cnt++;
    for(int i = 0; i < 8; i += 2)
    {
        int ux = x + p[i], uy = y + p[i + 1];
        if(!vis[ux][uy] && (s[ux][uy] == 'K' || s[ux][uy] == '.'))
            dfs(ux, uy);
    }
}

int NowaWarownia(int r, int c)
{
    s[r][c] = 'W';
    cnt = 0;
    if(ile == 0) return 1;
    for(int i = 1; i <= n1; i++)
        for(int j = 1; j <= m1; j++)
            vis[i][j] = 0;
    dfs(pos[0].first, pos[0].second);
    if(cnt == ile) return 1;
    s[r][c] = '.';
    return 0;
}

void PrzeniesOsade(int r1, int c1, int r2, int c2)
{
    s[r1][c1] = '.';
    s[r2][c2] = 'K';
}