[Link] https://www.acmicpc.net/problem/17135
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
75
76
77
78
79
#include <algorithm>
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <cstring>
#include <stack>
// #include <bits/stdc++.h>
using namespace std;
#define for0(i, n) for(int i = 0; i < n; i++)
#define for1(i, n) for(int i = 1; i < n; i++)
#define fori(s, e) for(int i = s; i < e; i++)
#define ll long long
#define endl "\n"
#define nulls '\0'
#define dkdk " "
const int MAX = 5e5 + 1;
const int INF = 987654321;
int n, m, d, ans, enemy_cnt;
bool mm[15][15];
bool tmp[15][15];
bool swap_arr[15][15];
set<pair<int,int>> kill;
vector<int> list;
void calc() {
for0(i, n) for0(j, m) tmp[i][j] = mm[i][j];
int e_cnt = enemy_cnt, kill_cnt = 0;
while(e_cnt) {
kill.clear();
for0(k, 3) {
memset(swap_arr, 0, sizeof(swap_arr));
int min_dis = INF, ii = 0, jj = 0;
for0(i, n) for0(j, m) {
if(tmp[i][j] == false) continue;
if(abs(j - list[k]) + n - i == min_dis) {
if(j < jj) ii = i, jj = j;
}
else if(abs(j - list[k]) + n - i < min_dis) {
min_dis = abs(j - list[k]) + n - i;
ii = i, jj = j;
}
}
if(min_dis <= d) kill.insert({ ii, jj });
}
kill_cnt += (int)kill.size();
for(auto p: kill) tmp[p.first][p.second] = false;
for0(i, n-1) for0(j, m) swap_arr[i+1][j] = tmp[i][j];
e_cnt = 0;
for0(i, n) for0(j, m) { tmp[i][j] = swap_arr[i][j]; if(tmp[i][j]) e_cnt++; }
}
ans = max(ans, kill_cnt);
}
void dfs(int startIdx) {
if(list.size() == 3) {
calc();
return;
}
for(int i = startIdx; i < m; i++) {
list.push_back(i);
dfs(i+1);
list.pop_back();
}
}
int main() {
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
cin >> n >> m >> d;
for0(i, n) for0(j, m) {
int in; cin >> in;
if(in) { enemy_cnt++; mm[i][j] = true; }
}
dfs(0);
cout << ans;
return 0;
}