회원가입
로그인
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
전체
공지
자유
질문
오타/오역/요청
게시판 공지
홍보
업데이트
solved.ac
글쓰기
질문 도움말
자주묻는 질문
오류를 못찾겠습니다.
10026번 - 적록색약
kcj3054
3년 전
0
오류를 못찾겠습니다.
예제는 잘 나옵니다.
#include <iostream> #include <vector> #include <queue> #include <string> using namespace std; int n; string s[101]; char ch[3] = { 'R', 'G', 'B' }; int dx[] = { -1, 0, 1 , 0 }; int dy[] = { 0, 1, 0, -1 }; bool visit1[101][101]; bool visit2[101][101]; typedef struct point { int x; int y; }point; void bfs_normal(int x, int y, int color) {// 0 r, 1 g, 2 b queue<point> q; q.push({ x,y }); visit1[x][y] = 1; while (!q.empty()) { int x = q.front().x; int y = q.front().y; q.pop(); int nx = 0, ny = 0; for (int i = 0; i < 4; i++) { nx = x + dx[i]; ny = y + dy[i]; if (nx >= 0 && ny >= 0 && nx < n && ny < n && !visit1[nx][ny] && s[nx][ny] == ch[color]) { visit1[nx][ny] = 1; q.push({ nx, ny }); } } } } void bfs_ilnormal(int x, int y, int color) { // queue<point> q; q.push({ x,y }); visit2[x][y] = 1; while (!q.empty()) { int x = q.front().x; int y = q.front().y; q.pop(); int nx = 0, ny = 0; for (int i = 0; i < 4; i++) { nx = x + dx[i]; ny = y + dy[i]; // 0 r, 1 g, 2 b if (nx >= 0 && ny >= 0 && nx < n && ny < n && !visit2[nx][ny] ) { if (s[nx][ny] == ch[color]) { visit2[nx][ny] = 1; q.push({ nx, ny }); } else { //r, g 같은걸로 0 , 1 if ( (color == 0 || color == 1) && s[nx][ny] == 'R' || s[nx][ny] == 'G') { visit2[nx][ny] = 1; q.push({ nx, ny }); } } } } } } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cin >> n; for (int i = 0; i < n; i++) cin >> s[i]; int ans_normal = 0; for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { if (!visit1[i][j]) { for (int k = 0; k < 3; k++) { if (s[i][j] == ch[k]) { ans_normal++; bfs_normal(i, j, k); } } } } } cout << ans_normal <<" "; int ans_ilnormal = 0; for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { if (!visit2[i][j]) { for (int k = 0; k < 3; k++) { if (s[i][j] == ch[k]) { ans_ilnormal++; bfs_ilnormal(i, j, k); } } } } } cout << ans_ilnormal <<" "; return 0; }
kcj3054
3년 전
0
작성자 입니다 해결했습니다
댓글을 작성하려면
로그인
해야 합니다.
kcj3054 3년 전
오류를 못찾겠습니다.
예제는 잘 나옵니다.