회원가입
로그인
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
글쓰기
질문 도움말
자주묻는 질문
40프로에서 계속 틀리는데 이유를 모르겠습니다.
10875번 - 뱀
amstars
7년 전
1
지나온 길을 모두 선분으로 잡아 다음 이동할 크기만큼 이동이 올바른지 체크하였고 한칸씩이 아니라 방향잡아 쭉 한번에 이동으로 만들었습니다. 고수님들 40프로에서 왜 자꾸 틀리는지 모르겠습니다. 테스트케이스좀 알려주세요.
#include <stdio.h> #include <stdlib.h> #pragma warning(disable:4996) #define RIGHT 0 #define UP 1 #define LEFT 2 #define DOWN 3 typedef struct rotate1 { long long int t; char rotate; }rotate; typedef struct sunbun1 { long long int x1; long long int y1; long long int x2; long long int y2; }sunbun; long long int checkf(long long int x, long long int y, long long int dir, long long int t, long long int x1, long long int x2, long long int y1, long long int y2) { if (x1 == x2 && (y1<=y2&&y1<=y&&y<=y2)|| (y2<=y1&&y2 <= y&&y <= y1)) { if (dir == LEFT && x1 <= x && x-t <= x1) { return x - x1; } if (dir == RIGHT && x1 >= x && x + t >= x1) { return x1 - x; } } else if (y1 == y2 && (x1 <= x2&&x1 <= x&&x <= x2) || (x2 <= x1&&x2 <= x&&x <= x1)) { if (dir == DOWN && y1 <= y && y - t <= y1) { return y - y1; } if (dir == UP && y1 >= y && y + t >= y1) { return y1 - y; } } return 0; } int main() { int check = 1; long long int x; long long int y; int tmpx; int tmpy; int direction = RIGHT; int trans = 0; long long int time = 0; int L; int N; int i; int j; long long int tmp; long long int temp; int tt; sunbun* s; rotate* r; scanf("%d", &L); scanf("%d", &N); r = (rotate*)malloc(sizeof(rotate)*(N + 1));//1부터 s = (sunbun*)malloc(sizeof(sunbun)*(N + 2));//1부터 for (i = 1; i <= N; i++) { scanf("%lld %c",&r[i].t,&r[i].rotate); } x = 0; y = 0; s[1].x1 = 0; s[1].y1 = 0;//원점방문한다. if (x + r[1].t > L) { time += (L - x) + 1; x = L; printf("%lld", time); return 1; } time += r[1].t; x += r[1].t; if (r[1].rotate == 'L') { if (direction == DOWN) direction = RIGHT; else direction += 1; } else { if (direction == RIGHT) direction = DOWN; else direction -= 1; } s[1].x2 = x; s[1].y2 = y;//원점방문한다. check = 1; for (i = 2; i <= N; i++) { s[check+1].x1 = x; s[check+1].y1 = y;//원점방문한다. if (direction == RIGHT) { tmp = checkf(x, y, direction, r[i].t, s[check].x1, s[check].x2, s[check].y1, s[check].y2); for (j = check-1; j >= 1; j--) { temp = checkf(x, y, direction, r[i].t, s[j].x1, s[j].x2, s[j].y1, s[j].y2); if (temp != 0 && tmp == 0) tmp = temp; else if (temp != 0 && tmp>temp) tmp = temp; } if (tmp != 0) { time += tmp; printf("%lld", time); return 1; } if (x + r[i].t > L) { time += (L - x) + 1; x = L; printf("%lld", time); return 1; } x += r[i].t; time += r[i].t; } else if (direction == LEFT) { tmp= checkf(x, y, direction, r[i].t, s[check].x1, s[check].x2, s[check].y1, s[check].y2);//!! for (j = check-1; j >= 1; j--) { temp = checkf(x, y, direction, r[i].t, s[j].x1, s[j].x2, s[j].y1, s[j].y2); if (temp != 0 && tmp == 0) tmp = temp; else if (temp != 0 && tmp>temp) tmp = temp; } if (tmp != 0) { time += tmp; printf("%lld", time); return 1; } if (x - r[i].t < -L) { time += -((-L) - x) + 1; x = -L; printf("%lld", time); return 1; } x -= r[i].t; time += r[i].t; } else if (direction == UP) { tmp = checkf(x, y, direction, r[i].t, s[check].x1, s[check].x2, s[check].y1, s[check].y2); for (j = check-1; j >= 1; j--) { temp = checkf(x, y, direction, r[i].t, s[j].x1, s[j].x2, s[j].y1, s[j].y2); if (temp != 0 && tmp == 0) tmp = temp; else if (temp != 0 && tmp>temp) tmp = temp; } if (tmp != 0) { time += tmp; printf("%lld", time); return 1; } if (y + r[i].t > L) { time += (L - y) + 1; y = L; printf("%lld", time); return 1; } y += r[i].t; time += r[i].t; } else { tmp = checkf(x, y, direction, r[i].t, s[check].x1, s[check].x2, s[check].y1, s[check].y2); for (j = check-1; j >= 1; j--) { temp = checkf(x, y, direction, r[i].t, s[j].x1, s[j].x2, s[j].y1, s[j].y2); if (temp != 0 && tmp == 0) tmp = temp; else if (temp != 0 && tmp>temp) tmp = temp; } if (tmp != 0) { time += tmp; printf("%lld", time); return 1; } if (y - r[i].t < -L) { time += -((-L) - y) + 1; y = -L; printf("%lld", time); return 1; } y -= r[i].t; time += r[i].t; } s[++check].x2 = x; s[check].y2 = y;//원점방문한다. if (r[i].rotate == 'L') { if (direction == DOWN) direction = RIGHT; else direction += 1; } else { if (direction == RIGHT) direction = DOWN; else direction -= 1; } } if (direction == RIGHT) { tt = L - x; tmp = checkf(x, y, direction, tt, s[check].x1, s[check].x2, s[check].y1, s[check].y2); for (j = check-1; j >= 1; j--) { temp = checkf(x, y, direction, tt, s[j].x1, s[j].x2, s[j].y1, s[j].y2); if (temp != 0 && tmp == 0) tmp = temp; else if (temp != 0 && tmp>temp) tmp = temp; } if (tmp != 0) { time += tmp; printf("%lld", time); return 1; } time += -((-L) - x) + 1; x = -L; printf("%lld", time); return 1; } if (direction == LEFT) { tt = -L + x; tmp = checkf(x, y, direction, tt, s[check].x1, s[check].x2, s[check].y1, s[check].y2); for (j = check-1; j >= 1; j--) { temp = checkf(x, y, direction, tt, s[j].x1, s[j].x2, s[j].y1, s[j].y2); if (temp != 0 && tmp == 0) tmp = temp; else if (temp != 0 && tmp>temp) tmp = temp; } if (tmp != 0) { time += tmp; printf("%lld", time); return 1; } time += -((-L) - x) + 1; x = -L; printf("%lld", time); return 1; } if (direction == UP) { tt = L - y; tmp = checkf(x, y, direction, tt, s[check].x1, s[check].x2, s[check].y1, s[check].y2); for (j = check-1; j >= 1; j--) { temp = checkf(x, y, direction, tt, s[j].x1, s[j].x2, s[j].y1, s[j].y2); if (temp != 0 && tmp == 0) tmp = temp; else if (temp != 0 && tmp>temp) tmp = temp; } if (tmp != 0) { time += tmp; printf("%lld", time); return 1; } time += (L - y) + 1; y = L; printf("%lld", time); return 1; } if (direction == DOWN) { tt = -L + y; tmp = checkf(x, y, direction, tt, s[check].x1, s[check].x2, s[check].y1, s[check].y2); for (j = check-1; j >= 1; j--) { temp = checkf(x, y, direction, tt, s[j].x1, s[j].x2, s[j].y1, s[j].y2); if (temp != 0 && tmp == 0) tmp = temp; else if (temp != 0 && tmp>temp) tmp = temp; } if (tmp != 0) { time += tmp; printf("%lld", time); return 1; } time += -((-L) - y) + 1; y = -L; printf("%lld", time); return 1; } }
댓글을 작성하려면
로그인
해야 합니다.
amstars 7년 전 1