-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBOJ14500_Tetromino.cpp
More file actions
75 lines (69 loc) · 1.83 KB
/
BOJ14500_Tetromino.cpp
File metadata and controls
75 lines (69 loc) · 1.83 KB
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
//
// main.cpp
// BOJ14500_Tetromino
//
// Created by 신지식 on 2018. 9. 24..
// Copyright © 2018년 Shin Ji Sik. All rights reserved.
//
#include <iostream>
#include <algorithm>
using namespace std;
int arr[501][501];
int check[501][501];
int dx[4] = {1, -1, 0, 0};
int dy[4] = {0, 0 ,1, -1};
int ans = 0;
int n, m;
void go(int x, int y, int sum, int cnt){
if(cnt == 4){
ans = max(ans, sum);
return;
}
if(x < 0 || x >= n || y < 0 || y >= m) return;
if(check[x][y] == true) return;
check[x][y] = true;
for(int i = 0; i < 4; i++){
go(x+dx[i], y+dy[i], sum + arr[x][y], cnt + 1);
}
check[x][y] = false;
}
int main(){
cin >> n >> m;
for(int i = 0; i < n; i++){
for(int j = 0; j < m; j++){
cin >> arr[i][j];
}
}
for(int i = 0; i < n; i++){
for(int j = 0; j < m; j++){
go(i, j, 0, 0);
if(j + 2 < m){
int tmp = arr[i][j] + arr[i][j+1] + arr[i][j+2];
if(i - 1 >= 0){
int tmp2 = tmp + arr[i-1][j+1];
if(tmp2 > ans)
ans = tmp2;
}
if(i + 1 < n){
int tmp2 = tmp + arr[i+1][j+1];
if(tmp2 > ans)
ans = tmp2;
}
}
if(i + 2 < n){
int tmp = arr[i][j] + arr[i+1][j] + arr[i+2][j];
if(j + 1 < m){
int tmp2 = tmp + arr[i+1][j+1];
if(tmp2 > ans)
ans = tmp2;
}
if(j - 1 >= 0){
int tmp2 = tmp + arr[i+1][j-1];
if(tmp2 > ans)
ans = tmp2;
}
}
}
}
printf("%d\n", ans);
}