회원가입
로그인
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
글쓰기
질문 도움말
자주묻는 질문
질문드립니다.
15906번 - 변신 이동 게임
goun55
2년 전
0
테스트케이스는 맞게 나오는데, 제출하니 틀렸다고 나옵니다.
어디가 잘못된거죠>??
import java.util.PriorityQueue; import java.util.Scanner; class Node implements Comparable<Node>{ int x; int y; int change; int c; Node(int x,int y,int change, int c){ this.x=x; this.y=y; this.change=change; this.c=c; } @Override public int compareTo(Node o) { return this.c - o.c; } } class Main { public static int[][][] dist; public static int[][] map; public static int n,t,r,c; public static int[] dx = {0,0,1,-1}; public static int[] dy = {1,-1,0,0}; public static void main(String[] args) { Scanner sc = new Scanner(System.in); n=sc.nextInt(); t=sc.nextInt(); r=sc.nextInt(); c=sc.nextInt(); map = new int[n+1][n+1]; dist = new int[2][n+1][n+1]; //2는 일반탐색인지, 워프탐색인지를 확인하기 위함이다. for(int i=1; i<=n; i++) { String s=sc.next(); for(int j=1; j<=n; j++) { char ss = s.charAt(j-1); if(ss=='#') map[i][j]=1; else map[i][j]=0; dist[0][i][j]=Integer.MAX_VALUE; dist[1][i][j]=Integer.MAX_VALUE; } } PriorityQueue<Node> q = new PriorityQueue<>(); q.add(new Node(1,1,0,0)); dist[0][1][1]=0; while(!q.isEmpty()) { Node tmp = q.poll(); if(tmp.x==r && tmp.y==c) { System.out.print(tmp.c); return; } if(tmp.c>dist[0][tmp.x][tmp.y]) continue; //일반탐색 for(int i=0; i<4; i++) { int nx = tmp.x+dx[i]; int ny = tmp.y+dy[i]; if(nx>=1 & ny>=1 && nx<=n && ny<=n) { if(dist[0][nx][ny]>tmp.c+1) { dist[0][nx][ny]=tmp.c+1 ; q.add(new Node(nx,ny,0,tmp.c+1)); } } } //워프탐색 for(int i=0; i<4;i++) { int nx = tmp.x+dx[i]; int ny = tmp.y+dy[i]; int newcost = tmp.c + t*(tmp.change==0 ? 1: 0) +1; while(true) { if(!range(nx, ny, n))break; if(nx>=1 && ny>=1 && nx<=n && ny<=n && map[nx][ny]==1) { if(dist[1][nx][ny]>newcost) { dist[1][nx][ny]=newcost; q.add(new Node(nx,ny,1,dist[1][nx][ny])); } break; } nx+=dx[i]; ny+=dy[i]; } } } } public static boolean range(int nr,int nc, int n) { return (nr>=1 && nc>=1 && nr<=n && nc<=n); } }
댓글을 작성하려면
로그인
해야 합니다.
goun55 2년 전
테스트케이스는 맞게 나오는데, 제출하니 틀렸다고 나옵니다.
어디가 잘못된거죠>??