๋ฌธ์ ๋งํฌ
1028๋ฒ: ๋ค์ด์๋ชฌ๋ ๊ด์ฐ (acmicpc.net)
๊ฐ์ฅ ํฐ ๋ค์ด์๋ชฌ๋์ ํฌ๊ธฐ๋ฅผ ์ถ๋ ฅํ๋ ๋ฌธ์ .
size 1: size 2: size 3:
1
1 1 1
1 1 1 1 1
1 1 1
1
๋ค์ด์๋ชฌ๋์ ํํ๋ ์ด๋ฌํ๋ค.
ํ์ด
๋ฌธ์ ๋ถ๋ฅ๊ฐ DP ์ธ๊ฒ์ ๋ณด๊ณ ์ฒ์์ ์์ํ๋ค. ์ฐจ๋ผ๋ฆฌ ๋ถํ ์ ๋ณต๋ฌธ์ ๋ฉด ๋ชฐ๋ผ๋ ์ด๊ฑธ ์ด๋ป๊ฒ DP๋ก ํธ๋ ์ง ๋์ ํ ๊ฐ์ด ์กํ์ง ์์๋ค. ๊ตฌ๊ธ ์ ์ ๋ฐฐ๋๋ค์ ํํธ๋ฅผ ๋ฐ์์ ํ์๋ค.
DP๋ฐฐ์ด์ ์ผ์ชฝ ์๋๋ก ์ต๋ ๋๊ฐ์ ์ ๊ธธ์ด, ์ค๋ฅธ์ชฝ ์๋๋ก ์ต๋ ๋๊ฐ์ ์ ๊ธธ์ด๋ฅผ ์ ์ฅํ๋ ๊ฒ์ด์๋ค.
Left, Right ๋ผ๋ 2์ฐจ์ ๋ฐฐ์ด์ ์ ์ธํด์ ๊ฐ ์ ๋ง๋ค ์ผ์ชฝ, ์ค๋ฅธ์ชฝ ์๋ ์ต๋ ๋๊ฐ์ ๊ธธ์ด๋ฅผ ์ ์ฅํด๋์๋ค.
์ด๊ฒ์ด ์ ํ์ํ๋๋?
ํน์ ํ ์ธ ์ A,B,C ๋ฅผ ์ก์์ A์์์ ์ผ์ชฝ ๋๊ฐ์ , ์ค๋ฅธ์ชฝ ๋๊ฐ์ ์ ๊ธธ์ด B์์์ ์ค๋ฅธ์ชฝ ๋๊ฐ์ ๊ธธ์ด, C์์์ ์ผ์ชฝ ๋๊ฐ์ ๊ธธ์ด๊ฐ ๋ชจ๋ ์์์ ์ X ์ด์์ด๋ฉด ํฌ๊ธฐ๊ฐ i ์ธ ๋ค์ด์๋ชฌ๋๋ฅผ ๋ง๋ค ์ ์๋ค๋ ๋ป์ด๋ค.
์ฌ๊ธฐ์ ์ A๋ฅผ ์์๋ก ( y , x ) ๋ผ๊ณ ํ๋ค๋ฉด
์ B๋ ( y + i - 1, x - ( i - 1 ))๋ก
์ C๋ ( y + i - 1, x + (i - 1 ))๋ก ๋ํ๋ผ ์ ์๋ค.
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
|
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <cstdio>
#include <string.h>
#include <string>
#include <stack>
#include <vector>
#include <math.h>
#include <queue>
#include <climits>
#include <algorithm>
#include <iomanip>
#include <map>
#define mod 1000000007
using namespace std;
typedef long long ll;
typedef priority_queue<pair<pair<ll, int>, int>, vector<pair<pair<ll, int>, int>>, greater<pair<pair<ll, int>, int>>> Priority_queue;
const int INF = INT_MAX;
const int MAX_N = 750 + 5;
int mine[MAX_N][MAX_N];
int R, C;
int Left[MAX_N][MAX_N];
int Right[MAX_N][MAX_N];
bool is_ok(int y, int x) {
if (y < 0 || y >= R || x < 0 || x >= C)
return false;
return true;
}
int Find_LD(int y, int x) {
if (!mine[y][x])
return 0;
if (is_ok(y - 1, x + 1) && Left[y - 1][x + 1] > 1)
return Left[y - 1][x + 1] - 1;
int ret = 1;
while (is_ok(y + 1, x - 1)) {
y++; x--;
if (mine[y][x])
ret++;
else break;
}
return ret;
}
int Find_RD(int y, int x) {
if (!mine[y][x])
return 0;
if (is_ok(y - 1, x - 1) && Right[y - 1][x - 1] > 1)
return Right[y - 1][x - 1] - 1;
int ret = 1;
while (is_ok(y + 1, x + 1)) {
y++; x++;
if (mine[y][x])
ret++;
else break;
}
return ret;
}
int main(void) {
//ios_base::sync_with_stdio(false);
//cin.tie(NULL);
cin >> R >> C;
int ans = 0;
for (int i = 0; i < R; i++) {
for (int j = 0; j < C; j++) {
scanf("%1d", &mine[i][j]);
if (mine[i][j])
ans = 1;
}
}
if (ans == 0) {
cout << "0\n";
return 0;
}
for (int i = 0; i < R; i++) {
for (int j = 0; j < C; j++) {
Left[i][j] = Find_LD(i, j);
Right[i][j] = Find_RD(i, j);
}
}
for (int i = 2; i <= (max(R, C) + 1) / 2; i++) {
bool chk = false;
for (int k = 0; k <= R - (2 * i - 2); k++) {
for (int j = i - 1; j <= C - i + 1; j++) {
pair<int, int> dot1 = { k,j };
pair<int, int> dot2 = { k + i - 1, j + i - 1 };
pair<int, int> dot3 = { k + i - 1, j - (i - 1) };
if (!is_ok(dot1.first, dot1.second) || !is_ok(dot2.first, dot2.second) || !is_ok(dot3.first, dot3.second))
continue;
if (Left[dot1.first][dot1.second] >= i && Right[dot1.first][dot1.second] >= i
&& Left[dot2.first][dot2.second] >= i && Right[dot3.first][dot3.second] >= i) {
ans = max(ans, i);
chk = true;
break;
}
}
if (chk)
break;
}
}
cout << ans << "\n";
return 0;
}
|
cs |
Find_LD() , Find_RD() ํจ์๋ ๊ฐ๊ฐ ์ผ์ชฝ, ์ค๋ฅธ์ชฝ ๋๊ฐ์ ์ ๊ธธ์ด๋ฅผ ์ฐพ์์ฃผ๋ ํจ์์ด๋ค.
'๋ฐฑ์ค > Platinum' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[BOJ] 5373 : ํ๋น (0) | 2022.05.16 |
---|---|
[BOJ] 10251 : ์ด์ ๋ฉดํ ์ํ (0) | 2022.03.25 |
[BOJ] 13308 : ์ฃผ์ ์ (0) | 2022.03.15 |
[BOJ] 10272 : ํ์๊ธ ์ฌ๋ฅ๊พผ ๊น์ ์ (0) | 2022.03.11 |
[BOJ] 2842 : ์ง๋ฐฐ์ ํ์๋ (0) | 2022.03.10 |