회원가입
로그인
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
문제집
대회
2
채점 현황
랭킹
게시판
그룹
블로그
강의
전체
공지
자유
질문
오타/오역/요청
게시판 공지
홍보
업데이트
solved.ac
글쓰기
질문 도움말
자주묻는 질문
뭐가 틀린건지... -_-
14502번 - 연구소
us10
3년 전
0
뭐가 틀린건지.. 도무지. 감이..
반례가 있을지요 잠을 못자네요 이거
#include <iostream> using namespace std; #define MIN 3 #define MAX 20 int matrix[MAX][MAX]; int virus_matrix[MAX][MAX]; //int visited[MAX][MAX]; int temp_matrix[MAX][MAX]; int N, M; int dx[4] = { 0, 0, -1, 1 }; int dy[4] = { -1, 1, 0, 0 }; typedef struct _pos { int row; int col; } Pos; int result; int max_result = -1; Pos queue[MAX*MAX]; int front, rear; void Enqueue(Pos p) { queue[front++] = p; } Pos Dequeue() { return queue[rear++]; } bool IsEmptyQueue() { return front == rear; } void copy_matrix(int (*src)[MAX], int (*dest)[MAX]) { for (int i = 0; i < N; i++) { for (int j = 0; j < M; j++) { dest[i][j] = src[i][j]; } } } bool IsValid(Pos p) { if ((p.row >= 0 && p.row < N) && (p.col >= 0 && p.col < M) && (virus_matrix[p.row][p.col] == 0) ) { return true; } else { return false; } } void BFS() { front = rear = 0; result = 0; copy_matrix(temp_matrix, virus_matrix); Pos p; for (int i = 0; i < N; i++) { for (int j = 0; j < M; j++) { if (virus_matrix[i][j] == 2) { p = { i, j }; Enqueue(p); } } } while (!IsEmptyQueue()) { p = Dequeue(); virus_matrix[p.row][p.col] = 2; for (int i = 0; i < 4; i++) { Pos temp = { p.row + dx[i], p.col + dy[i] }; if (IsValid(temp)) { //virus_matrix[p.row][p.col] = 2; Enqueue(temp); } } } for (int i = 0; i < N; i++) { for (int j = 0; j < M; j++) { if (virus_matrix[i][j] == 0) { result++; } } } if (max_result < result) { max_result = result; } } void make_wall(int cnt) { if (cnt == 0) { BFS(); return ; } for (int i = 0; i < N; i++) { for (int j = 0; j < M; j++) { if (temp_matrix[i][j] == 0) { temp_matrix[i][j] = 1; make_wall(cnt - 1); temp_matrix[i][j] = 0; } } } } int main() { cin >> N >> M; for (int i = 0; i < N; i++) { for (int j = 0; j < M; j++) { cin >> matrix[i][j]; } } copy_matrix(matrix, temp_matrix); make_wall(3); cout << max_result << "\n"; #if 0 cout << "\n"; for (int i = 0; i < N; i++) { for (int j = 0; j < M; j++) { cout << temp_matrix[i][j] << " "; } cout << "\n"; } #endif system("pause"); return 0; }
댓글을 작성하려면
로그인
해야 합니다.
us10 3년 전
뭐가 틀린건지.. 도무지. 감이..
반례가 있을지요 잠을 못자네요 이거