https://www.acmicpc.net/problem/2468
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 |
#include<iostream> #include<vector> #include<algorithm> #define INF -987654321; using namespace std;
int N; int dy[4] = {1,-1,0,0}; int dx[4] = {0,0,1,-1};
bool DFS(int y,int x,vector<vector<bool>>& check){ if(y>=N||x>=N||x<0||y<0) return true;
if(!check[y][x]) check[y][x] = true; else return true;
for(int i=0;i<4;i++){ int ny = y + dy[i]; int nx = x + dx[i];
DFS(ny,nx,check); }
return false;
}
int DFS_Start(vector<vector<int>>& v,vector<vector<bool>>& check){ int cnt=0;
for(int i=0;i<N;i++){ for(int j=0;j<N;j++){ if(!DFS(i,j,check)){ cnt++; } } } return cnt; }
int main(){ ios::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL); int MAX_VALUE = INF; cin>>N;
vector<vector<int>> v(N,vector<int>(N,0));
for(int i=0;i<N;i++){ for(int j=0;j<N;j++){ cin>>v[i][j]; } }
for(int k=0;k<=100;k++){ vector<vector<bool>> check(N,vector<bool>(N,false)); for(int i=0;i<N;i++){ for(int j=0;j<N;j++){ if(v[i][j]<=k) check[i][j] = true; } }
MAX_VALUE = max(MAX_VALUE,DFS_Start(v,check)); } cout<< MAX_VALUE; } |
'ProgramSoliving' 카테고리의 다른 글
백준 : 9251 (0) | 2020.01.01 |
---|---|
백준 : 3055 (0) | 2020.01.01 |
백준 : 14888 (0) | 2019.12.25 |
백준 : 14889 (0) | 2019.12.25 |
백준 : 1931* (0) | 2019.12.21 |