회원가입
로그인
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
문제집
대회
채점 현황
랭킹
게시판
그룹
더 보기
재채점 기록
블로그
강의
실험실
도움말
BOJ Stack
BOJ Book
전체
공지
자유
질문
오타/오역/요청
게시판 공지
홍보
업데이트
solved.ac
글쓰기
질문 도움말
자주묻는 질문
주석있습니다.. 반례는 다맞는데 34퍼에서 틀리네요.. 반례찾아주세요
17071번 - 숨바꼭질 5
gks10101
1년 전
0
주석있습니다.. 반례는 다맞는데 34퍼에서 틀리네요.. 반례찾아주세요
#include<stdio.h> #include<string.h> #include<stdlib.h> #include<math.h> typedef struct data { int x; int who; ///1수빈 2동생 }coord; coord xp[50000000]; //que int rear = 0; int front = 0; int check[500005]; int subin, bro; int ans = -1; int time = 1; void bfs() { while (rear != front) { int x = xp[front].x; int who = xp[front++].who; if (who == 2) { //동생 if (x + time > 500000) { //50만넘으면 -1 printf("-1"); exit(0); } if (check[x + time] != 0) { //동생이 도달한곳에 수빈이가 왔던곳 if (check[x + time] == 3) { //수빈이가 홀수초 짝수초 가능하다면 ans = time; break; } else if (check[x + time] == 2) { //수빈이가 짝수초 가능하다면 if (time % 2 == 0) { //time이 짝수여야함 ans = time; break; } } else if (check[x + time] == 1) { //수빈이가 홀수초 가능하다면 if (time % 2 == 1) { //time이 홀수여야함 ans = time; break; } } } xp[rear].x = x + time; xp[rear++].who = 2; time++; //타임업 } else { //수빈이 if (x - 1 >= 0) { if (check[x - 1] == 0) { if (check[x] == 1) check[x - 1] = 2; //홀수초에서 짝수초 else check[x - 1] = 1; //짝수초에서 홀수초 xp[rear].x = x - 1; xp[rear++].who = who; } else if (check[x - 1] == 1) { //홀수초로 갈수 있는곳에 if (check[x] == 1||check[x]==3) { ///짝수초로갈수있다면 check[x - 1] = 3; xp[rear].x = x - 1; xp[rear++].who = who; } } else if (check[x - 1] == 2) { //짝수초로 갈수 있는곳에 if (check[x] == 2 || check[x] == 3) { ///홀수초로갈수있다면 check[x - 1] = 3; xp[rear].x = x - 1; xp[rear++].who = who; } } } if (x + 1 <= 500000) { if (check[x + 1] == 0) { if (check[x] == 1) check[x + 1] = 2; else check[x + 1] = 1; xp[rear].x = x + 1; xp[rear++].who = who; } else if (check[x + 1] == 1) { if (check[x] == 1 || check[x] == 3) { check[x +1] = 3; xp[rear].x = x + 1; xp[rear++].who = who; } } else if (check[x + 1] == 2) { if (check[x] == 2 || check[x] == 3) { check[x + 1] = 3; xp[rear].x = x + 1; xp[rear++].who = who; } } } if (x * 2 <= 500000) { if (check[x*2] == 0) { if (check[x] == 1) check[x *2] = 2; else check[x *2] = 1; xp[rear].x = x *2; xp[rear++].who = who; } else if (check[x *2] == 1) { if (check[x] == 1 || check[x] == 3) { check[x *2] = 3; xp[rear].x = x *2; xp[rear++].who = who; } } else if (check[x *2] == 2) { if (check[x] == 2 || check[x] == 3) { check[x *2] = 3; xp[rear].x = x *2; xp[rear++].who = who; } } } } } } int main() { scanf("%d %d", &subin, &bro); if (subin == bro) { printf("0"); return 0; } check[subin] = 2; //0초는 짝수초로 가정 xp[rear].x = subin; xp[rear++].who = 1; xp[rear].x = bro; xp[rear++].who = 2; bfs(); if (ans == -1) printf("-1"); else printf("%d", ans); }
댓글을 작성하려면
로그인
해야 합니다.
gks10101 1년 전
주석있습니다.. 반례는 다맞는데 34퍼에서 틀리네요.. 반례찾아주세요