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
#include "bits/stdc++.h"
using namespace std;

#include "osalib.h"

const int N = 1000;
namespace {
char board[N][N];

int n, m;

int Dfs(vector<vector<int>>& vis, int r, int c) {
    if (r < 0 || r >= n || c < 0 || c >= m) return 0;
    if (vis[r][c]) return 0;
    int acc = 0;
    if (board[r][c] == 'K') ++acc;
    if (board[r][c] == 'W') return 0;
    vis[r][c] = 1;
    for (int i = -1; i <= 1; ++i) {
        for (int j = -1; j <= 1; ++j) {
            if (i * i + j * j == 1) {
                acc += Dfs(vis, r+i, c+j);
            }
        }
    }
    return acc;
}

}

void NowaWyspa(int n_, int m_, char **board_) {
    n = n_;
    m = m_;
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < m; ++j) {
            board[i][j] = board_[i][j];
        }
    }
}

int NowaWarownia(int r, int c) {
    --r; --c;
    if (board[r][c] == 'K' || board[r][c] == 'W') return 0;
    board[r][c] = 'W';
    vector<vector<int>> vis(n, vector<int>(m, 0));
    int ile = 0;
    for (int i = -1; i <= 1; ++i) {
        for (int j = -1; j <= 1; ++j)  {
            if (i*i + j*j == 1) {
                if(Dfs(vis, r+i, c+j)) ++ile;
                if (ile >= 2) {
                    board[r][c] = '.';
                    return 0;
                }
            }

        }
    }
    return 1;
}

void PrzeniesOsade(int r1, int c1, int r2, int c2) {
    --r1; --c1; --r2; --c2;
    swap(board[r1][c1], board[r2][c2]);
}