-
Notifications
You must be signed in to change notification settings - Fork 0
/
swea2117.cpp
72 lines (60 loc) · 1.38 KB
/
swea2117.cpp
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
#include <cmath>
#include <vector>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
int price[42];
int cnt[42];
int mat[20][20];
int dx[4] = { 1, -1, 0, 0 };
int dy[4] = { 0, 0, 1, -1 };
int main(void) {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
for (int i = 1; i <= 41; i++) {
price[i] = i*i + (i - 1)*(i - 1);
}
int tc;
cin >> tc;
for (int test_case = 1; test_case <= tc; test_case++) {
int n, m;
cin >> n >> m;
vector<pair<int, int>> homelist;
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
cin >> mat[i][j];
if (mat[i][j] == 1) {
homelist.push_back(make_pair(i, j));
}
}
}
int ans = 0;
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
memset(cnt, 0, sizeof(cnt));
int maxdist = -1;
for (int k = 0; k < homelist.size(); k++) {
int x = homelist[k].first;
int y = homelist[k].second;
int distance = abs(i - x) + abs(j - y) + 1;
cnt[distance] += 1;
maxdist = max(maxdist, distance);
}
for (int k = 1; k <= maxdist; k++) {
cnt[k] += cnt[k - 1];
}
int tmpmax = -1;
for (int k = 1; k <= maxdist; k++) {
int tmpprice = m * cnt[k] - price[k];
if (tmpprice >= 0) {
tmpmax = max(tmpmax, cnt[k]);
}
}
ans = max(ans, tmpmax);
}
}
cout << "#" << test_case << " " << ans << '\n';
}
return 0;
}