Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <algorithm>
- #include <cstring>
- #include <vector>
- #include <set>
- #include <map>
- #include <stack>
- using namespace std;
- typedef long long ll;
- const int maxn = 222;
- const int maxk = 55;
- char mat[maxn][maxn];
- int L[maxn][maxn][maxk];
- int R[maxn][maxn][maxk];
- int up[maxn][maxn][maxk];
- int down[maxn][maxn][maxk];
- int rows[maxn][maxn][maxk];
- int cols[maxn][maxn][maxk];
- int main() {
- ios_base::sync_with_stdio(false);
- int n, m, k;
- cin >> n >> m >> k;
- for(int i = 0; i < n; i++) {
- for(int j = 0; j < m; j++) {
- cin >> mat[i][j];
- }
- }
- for(int x = 0; x <= k; x++) {
- for(int i = 0; i < n; i++) {
- for(int j = 0; j < m; j++) {
- int tmp_x = x;
- if(mat[i][j] == '*') {
- tmp_x--;
- }
- if(tmp_x < 0) {
- up[i][j][x] = 0;
- }
- else {
- up[i][j][x] = 1;
- if(i > 0) {
- up[i][j][x] += up[i - 1][j][tmp_x];
- }
- }
- }
- }
- }
- for(int x = 0; x <= k; x++) {
- for(int i = n - 1; i >= 0; i--) {
- for(int j = m - 1; j >= 0; j--) {
- int tmp_x = x;
- if(mat[i][j] == '*') {
- tmp_x--;
- }
- if(tmp_x < 0) {
- down[i][j][x] = 0;
- }
- else {
- down[i][j][x] = 1;
- if(i + 1 < n) {
- down[i][j][x] += down[i + 1][j][tmp_x];
- }
- }
- }
- }
- }
- for(int x = 0; x <= k; x++) {
- for(int i = 0; i < n; i++) {
- for(int j = 0; j < m; j++) {
- int tmp_x = x;
- if(mat[i][j] == '*') {
- tmp_x--;
- }
- if(tmp_x < 0) {
- L[i][j][x] = 0;
- }
- else {
- L[i][j][x] = 1;
- if(j > 0) {
- L[i][j][x] += L[i][j - 1][tmp_x];
- }
- }
- }
- }
- }
- for(int x = 0; x <= k; x++) {
- for(int i = n - 1; i >= 0; i--) {
- for(int j = m - 1; j >= 0; j--) {
- int tmp_x = x;
- if(mat[i][j] == '*') {
- tmp_x--;
- }
- if(tmp_x < 0) {
- R[i][j][x] = 0;
- }
- else {
- R[i][j][x] = 1;
- if(j + 1 < m) {
- R[i][j][x] += R[i][j + 1][tmp_x];
- }
- }
- }
- }
- }
- for(int i = 0; i < n; i++) {
- for(int j = 0; j < m; j++) {
- for(int x = 0; x <= k; x++) {
- rows[i][j][x] = 0;
- int tmp_x = x;
- if(mat[i][j] == '*') {
- tmp_x--;
- }
- if(tmp_x >= 0) {
- for(int y = 0; y <= tmp_x; y++) {
- int tmp_y = tmp_x - y;
- int sum = 1;
- if(i + 1 < n) {
- sum += down[i + 1][j][tmp_y];
- }
- if(i > 0) {
- sum += up[i - 1][j][y];
- }
- rows[i][j][x] = max(rows[i][j][x], sum);
- }
- }
- }
- }
- }
- for(int i = 0; i < n; i++) {
- for(int j = 0; j < m; j++) {
- for(int x = 0; x <= k; x++) {
- cols[i][j][x] = 0;
- int tmp_x = x;
- if(mat[i][j] == '*') {
- tmp_x--;
- }
- if(tmp_x >= 0) {
- for(int y = 0; y <= tmp_x; y++) {
- int tmp_y = tmp_x - y;
- int sum = 1;
- if(j + 1 < m) {
- sum += R[i][j + 1][y];
- }
- if(j > 0) {
- sum += R[i][j - 1][tmp_y];
- }
- cols[i][j][x] = max(cols[i][j][x], sum);
- }
- }
- }
- }
- }
- int result= 0;
- for(int i = 0; i < n; i++) {
- for(int j = 0; j < m; j++) {
- int tmp_x = k;
- int obstacle = 0;
- if(mat[i][j] == '*') {
- tmp_x--;
- obstacle = 1;
- }
- if(tmp_x >= 0) {
- for(int x = 0; x <= tmp_x; x++) {
- int y = tmp_x - x;
- int r_tmp = x + obstacle;
- int c_tmp = y + obstacle;
- result = max(result, rows[i][j][r_tmp] + cols[i][j][c_tmp] - 1);
- }
- }
- }
- }
- cout << result - 1 << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement