회원가입
로그인
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
글쓰기
질문 도움말
자주묻는 질문
로직 오류를 못찾겠습니다
14503번 - 로봇 청소기
awd040620
1년 전
0
시간초과도 나고 로직오류도 못찾겠습니다ㅠㅠ
#include <bits/stdc++.h> using namespace std; #define X first #define Y second int N,M,d; int robot_x,robot_y; int robot_dx,robot_dy; int board[52][52]; int dx[]={-1,0,1,0}; // 북,동,남,서 int dy[]={0,1,0,-1}; bool clean(int x,int y){ if(board[x][y]==0) return false; //청소되지 않은 빈칸 else return true; } bool nearclean(int x,int y){ for(int i=0;i<4;i++){ if(board[x+dx[i]][y+dy[i]]==0) return false; //주변 4칸중 청소되지 않은 빈칸있다면 false } return true; } bool isbackup(int x,int y,int dirx,int diry){ if(board[x+dx[(dirx+2)%4]][y+dy[(diry+2)%4]]==1) return false; //후진 불가능 else return true; // 후진가능 } int main(void){ ios::sync_with_stdio(0); cin.tie(0); cin>>M>>N; cin>>robot_x>>robot_y; cin>>d; robot_dx=dx[d]; robot_dy=dy[d]; for(int i=0;i<N;i++){ for(int j=0;j<M;j++){ cin>> board[i][j]; } } bool operation =true; while(operation){ bool IsClean = clean(robot_x,robot_y); if(!IsClean) board[robot_x][robot_y]=2; bool NearClean = nearclean(robot_x,robot_y); if(NearClean){ if(isbackup(robot_x,robot_y,robot_dx,robot_dy)){ robot_x+=dx[(robot_dx+2)%4]; robot_y+=dy[(robot_dy+2)%4]; continue; } else{ operation=false; break; } } else{ for(int i=0;i<4;i++){ robot_dx=dx[(robot_dx+3)%4]; robot_dy=dy[(robot_dy+3)%4]; if(board[robot_x+robot_dx][robot_y+robot_dy]==0){ robot_x+=robot_dx; robot_y+=robot_dy; break; } } } } int ans=0; for(int i=0;i<N;i++){ for(int j=0;j<M;j++){ if(board[i][j]==2){ ans++; } } } cout<<ans; }
댓글을 작성하려면
로그인
해야 합니다.
awd040620 1년 전
시간초과도 나고 로직오류도 못찾겠습니다ㅠㅠ