회원가입
로그인
Toggle navigation
문제
문제
전체 문제
문제 출처
단계별로 풀어보기
알고리즘 분류
추가된 문제
문제 순위
문제
푼 사람이 한 명인 문제
아무도 못 푼 문제
최근 제출된 문제
최근 풀린 문제
랜덤
출처
ICPC
Olympiad
한국정보올림피아드
한국정보올림피아드시․도지역본선
전국 대학생 프로그래밍 대회 동아리 연합
대학교 대회
카카오 코드 페스티벌
Coder's High
ICPC
Regionals
World Finals
Korea Regional
Africa and the Middle East Regionals
Europe Regionals
Latin America Regionals
North America Regionals
South Pacific Regionals
문제집
대회
1
채점 현황
랭킹
게시판
그룹
더 보기
재채점 기록
블로그
강의
실험실
도움말
BOJ Stack
BOJ Book
16988번 - Baaaaaaaaaduk2 (Easy)
BaaaaaaaaaaarkingDog
C++14
#include <bits/stdc++.h> using namespace std; #define X first #define Y second int dx[4] = {1,-1,0,0}; int dy[4] = {0,0,1,-1}; int board[22][22]; bool vis[22][22]; int n,m; vector<pair<int, int> > moves; int calc(pair<int,int> m1, pair<int,int> m2){ // m1, m2에 착수하고 BFS를 돌려 죽은 돌의 갯수를 계산하는 함수 int ret = 0; board[m1.X][m1.Y] = 1; board[m2.X][m2.Y] = 1; for(int i = 0; i < n; i++) for(int j = 0; j < m; j++) vis[i][j] = 0; for(int i = 0; i < n; i++){ for(int j = 0; j < m; j++){ if(vis[i][j] or board[i][j] != 2) continue; bool isdead = true; // 연결된 돌 중에 빈 칸과 닿아있는게 하나라도 있다면 이 변수를 false로 만들 것이다. queue<pair<int, int> > Q; Q.push(make_pair(i,j)); vis[i][j] = true; int area = 0; while(!Q.empty()){ area++; pair<int, int> cur = Q.front(); Q.pop(); for(int dir = 0; dir < 4; dir++){ int nx = cur.X+dx[dir]; int ny = cur.Y+dy[dir]; if(nx < 0 or nx >= n or ny < 0 or ny >= m) continue; if(board[nx][ny] == 0) isdead = false; if(vis[nx][ny] or board[nx][ny] != 2) continue; Q.push(make_pair(nx,ny)); vis[nx][ny] = true; } } if(isdead) ret += area; } } board[m1.X][m1.Y] = 0; board[m2.X][m2.Y] = 0; return ret; } int main(){ ios::sync_with_stdio(0); cin.tie(0); cin >> n >> m; for(int i = 0; i < n; i++){ for(int j = 0; j < m; j++){ cin >> board[i][j]; if(board[i][j] == 0){ moves.push_back(make_pair(i,j)); } } } int ans = 0; for(int i = 0; i < moves.size(); i++){ for(int j = i+1; j < moves.size(); j++){ ans = max(ans, calc(moves[i],moves[j])); } } cout << ans; }
결과
메모리
시간
코드 길이
맞았습니다!!
2028
440
1839