Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- typedef long long LL;
- const int maxn = 300 + 100;
- int n, k, ans, tmp;
- int num[maxn][maxn];
- set<int> st;
- const int dir[4][2] = {
- { 0, 0 }, { 0, 1 }, { 1, 0 }, { 1, 1 }
- };
- bool in(int x, int y) {
- return x >= 1 && x <= n && y >= 1 && y <= n;
- }
- bool judge(int x, int y) {
- st.clear();
- for (int i = 0; i < 4; ++i) {
- int xx = x + dir[i][0];
- int yy = y + dir[i][1];
- if (!in(xx, yy)) {
- return false;
- }
- st.insert(num[xx][yy]);
- }
- return st.size() >= 3;
- }
- int cal(int x, int y) {
- int ret = 0;
- for (int i = x - 1; i <= x; ++i) {
- for (int j = y - 1; j <= y; ++j) {
- if (judge(i, j)) {
- ++ret;
- }
- }
- }
- return ret;
- }
- int main() {
- #ifdef ExRoc
- freopen("test.txt", "r", stdin);
- #endif // ExRoc
- ios::sync_with_stdio(false);
- cin >> n >> k;
- for (int i = 1; i <= n; ++i) {
- for (int j = 1; j <= n; ++j) {
- cin >> num[i][j];
- }
- }
- for (int i = 1; i < n; ++i) {
- for (int j = 1; j < n; ++j) {
- if (judge(i, j)) {
- ++ans;
- }
- }
- }
- tmp = ans;
- k = min(k, 9);
- for (int i = 1; i <= n; ++i) {
- for (int j = 1; j <= n; ++j) {
- int a = cal(i, j);
- int tmpC = num[i][j];
- for (int c = 1; c <= k; ++c) {
- num[i][j] = c;
- int b = cal(i, j);
- ans = max(ans, tmp + b - a);
- }
- num[i][j] = tmpC;
- }
- }
- cout << ans << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement