회원가입
로그인
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
문제집
대회
채점 현황
게시판
그룹
더 보기
재채점 기록
블로그
도움말
전체
공지
자유
질문
오타/오역/요청
게시판 공지
홍보
업데이트
solved.ac
글쓰기
질문 도움말
자주묻는 질문
40% 에서 계속 틀립니다.
1245번 - 농장 관리
dksh_2023010518
1년 전
0
40% 에서 "틀렸습니다"가 뜹니다.
반례 부탁드립니다!
#include <iostream> #include <vector> #include <queue> struct GraphType{ int Value; bool IsVisited; }; struct BufferType{ int X, Y; }; bool isPeak(std::vector<std::vector<struct GraphType>>&, int, int); bool bfs(std::vector<std::vector<struct GraphType>>&, int, int, int); int main(int argc, char* argv[]){ int N, M; scanf("%d %d", &N, &M); std::vector<std::vector<struct GraphType>> graph(N+2, std::vector<struct GraphType>(M+2, {-1, false})); for(int i = 1; i <= N; i++){ for(int j = 1; j <= M; j++){ scanf("%d ", &graph[i][j].Value); } } int result = 0; for(int i = 1; i <= N; i++){ for(int j = 1; j <= M; j++){ if(graph[i][j].IsVisited){ continue; } if(graph[i][j].Value == 0){ continue; } if(!isPeak(graph, i, j)){ continue; } if(!bfs(graph, i, j, graph[i][j].Value)){ continue; } result++; } } printf("%d", result); return 0; } bool bfs(std::vector<std::vector<struct GraphType>>& graph, int x, int y, int p){ int N = graph.size(), M = graph[0].size(); std::queue<struct BufferType> buffer; buffer.push({x, y}); while(!buffer.empty()){ struct BufferType current = buffer.front(); buffer.pop(); if(current.X < 1 || current.Y < 1 || current.X > N || current.Y > M){ continue; } if(graph[current.X][current.Y].Value != p || graph[current.X][current.Y].IsVisited){ continue; } graph[current.X][current.Y].IsVisited = true; if(!isPeak(graph, current.X, current.Y)){ return false; } buffer.push({current.X + 1, current.Y}); buffer.push({current.X + 1, current.Y+1}); buffer.push({current.X + 1, current.Y-1}); buffer.push({current.X - 1, current.Y}); buffer.push({current.X - 1, current.Y+1}); buffer.push({current.X - 1, current.Y-1}); buffer.push({current.X, current.Y + 1}); buffer.push({current.X, current.Y - 1}); } return true; } bool isPeak(std::vector<std::vector<struct GraphType>>& graph, int i, int j){ if(graph[i][j].Value < graph[i+1][j].Value){ return false; } if(graph[i][j].Value < graph[i+1][j+1].Value){ return false; } if(graph[i][j].Value < graph[i+1][j-1].Value){ return false; } if(graph[i][j].Value < graph[i-1][j].Value){ return false; } if(graph[i][j].Value < graph[i-1][j+1].Value){ return false; } if(graph[i][j].Value < graph[i-1][j-1].Value){ return false; } if(graph[i][j].Value < graph[i][j+1].Value){ return false; } if(graph[i][j].Value < graph[i][j-1].Value){ return false; } return true; }
dksh_2023010518
1년 전
0
해결했습니다!
댓글을 작성하려면
로그인
해야 합니다.
dksh_2023010518 1년 전
40% 에서 "틀렸습니다"가 뜹니다.
반례 부탁드립니다!