회원가입
로그인
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
글쓰기
질문 도움말
자주묻는 질문
고수님들 반례좀 부탁드려요
31399번 - 아리스, 청소합니다! (Hard)
kyh05555
2년 전
0
푸는 방식이 잘못된 것일까요?
#include <iostream> #include <algorithm> #include <string> using namespace std; int H, W, R, C, D; bool dust_clear[1026][1026]; int RuleA[1026][1026]; int RuleB[1026][1026]; int isPassing[1026][1026][4]; int dx[4] = {0, 1, 0, -1}; int dy[4] = {-1, 0, 1, 0}; int result = 0; void Input() { cin >> H >> W; cin >> R >> C >> D; for (int i = 0; i < H; i++) { string str; cin >> str; for (int j = 0; j < W; j++) RuleA[i][j] = str[j] - '0'; } for (int i = 0; i < H; i++) { string str; cin >> str; for (int j = 0; j < W; j++) RuleB[i][j] = str[j] - '0'; } } void Solve() { int current_y = R; int current_x = C; int current_D = (RuleA[current_y][current_x] + D)%4; dust_clear[current_y][current_x] = true; int cnt = 0; bool trans = false; while (1) { int next_y = current_y + dy[current_D]; int next_x = current_x + dx[current_D]; int next_D; if (next_y < 0 || next_y >= H || next_x < 0 || next_x >= W) // 범위 밖으로 나갈 경우 break; if (isPassing[current_y][current_x][current_D] >= 3) // 먼지가 없는 타일에 3번이상 진입했을 경우(반복) break; if (dust_clear[next_y][next_x] == false) // 먼지가 있는 타일로 이동할 경우 { result += cnt + 1; cnt = 0; next_D = (RuleA[next_y][next_x] + current_D)%4; dust_clear[next_y][next_x] = true; trans = false; } else // 먼지가 없는 타일로 이동할 경우 { if (!trans) { trans = true; result++; cnt = -1; } cnt++; next_D = (RuleB[next_y][next_x] + current_D) % 4; isPassing[current_y][current_x][current_D]++; } current_y = next_y; current_x = next_x; current_D = next_D; } cout << result; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); Input(); Solve(); return 0; }
댓글을 작성하려면
로그인
해야 합니다.
kyh05555 2년 전
푸는 방식이 잘못된 것일까요?