Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- const int MAXN = 5e2 + 10;
- int Sala[MAXN][MAXN];
- int dx[] = {-1,-1, 0, 1,1,1,0,-1};
- int dy[] = { 0,-1,-1,-1,0,1,1, 1};
- bool OutOfRange(int x, int y, int L, int C)
- {
- if (x < 1 || x > L) return true;
- if (y < 1 || y > C) return true;
- return false;
- }
- int check_valid(int x, int y, int L, int C)
- {
- int resp = 8;
- for (int k = 0; k < 8; k++)
- {
- int hx = x + dx[k];
- int hy = y + dy[k];
- resp -= OutOfRange(hx, hy, L, C);
- }
- return resp;
- }
- void brincadeira(int x, int y, int L, int C)
- {
- int tempo = 1;
- while (tempo < L+C+1)
- {
- int validos = check_valid(x, y, L, C);
- int fora = Sala[x][y] / validos;
- Sala[x][y] = Sala[x][y] % validos;
- for (int k = 0; k < 8; k++)
- {
- int hx = x + dx[k];
- int hy = y + dy[k];
- if (OutOfRange(hx, hy, L, C)) continue;
- Sala[hx][hy] += fora;
- }
- int nextX; int nextY; int quantNext = -1;
- for (int k = 0; k < 8; k++)
- {
- int hx = x + dx[k];
- int hy = y + dy[k];
- if (OutOfRange(hx, hy, L, C)) continue;
- if (quantNext < Sala[hx][hy])
- {
- nextX = hx;
- nextY = hy;
- quantNext = Sala[hx][hy];
- }
- }
- x = nextX; y = nextY;
- tempo++;
- }
- }
- int main()
- {
- ios_base::sync_with_stdio(false);
- cin.tie(NULL);
- int L, C;
- cin >> L >> C;
- for (int i = 1; i <= L; i++)
- {
- for (int j = 1; j <= C; j++)
- {
- cin >> Sala[i][j];
- }
- }
- if (L == 1 && C == 1) {cout << Sala[1][1]; return 0;}
- int A, B;
- cin >> A >> B;
- brincadeira(A, B, L, C);
- int Max = -1;
- for (int i = 1; i <= L; i++)
- {
- for (int j = 1; j <= C; j++)
- {
- Max = max(Max, Sala[i][j]);
- }
- }
- cout << Max;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement