[BOJ] 1915 가장 큰 정사각형

Time Lapse :NONE

1915.cpp

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
#include <string>
#include <vector>
#include <iostream>
using namespace std;
int main(void) {
int N,M;
cin>>N>>M;
int answer = 0;
vector<string> MAP(N);
vector<vector<int>> DP(N+1,vector<int>(M+1,0));
for(int i=0;i<N;i++){
cin>>MAP[i];
}
for(int i=N-1;i>=0;i--){
for(int j=M-1;j>=0;j--){
if(MAP[i][j]=='0')
DP[i][j]=0;
else{
DP[i][j]=1+min(DP[i][j+1],min(DP[i+1][j],DP[i+1][j+1]));
}
answer = max(answer,DP[i][j]);
}
}
cout<<answer*answer<<endl;
}
Author: Song Hayoung
Link: https://songhayoung.github.io/2020/07/30/PS/BOJ/1915/
Copyright Notice: All articles in this blog are licensed under CC BY-NC-SA 4.0 unless stating additionally.