회원가입
로그인
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
문제집
대회
1
채점 현황
랭킹
게시판
그룹
더 보기
재채점 기록
블로그
강의
실험실
도움말
BOJ Stack
BOJ Book
전체
공지
자유
질문
오타/오역/요청
게시판 공지
홍보
업데이트
solved.ac
글쓰기
질문 도움말
자주묻는 질문
반례 부탁드립니다
17265번 - 나의 인생에는 수학과 함께
dlcksdnd321
4년 전
0
반례 부탁드립니다 ㅠㅠ
위에 나와있는 2가지는 맞았습니다
package AlgoStudy; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.PriorityQueue; import java.util.StringTokenizer; import javax.print.Doc; public class B17265 { static String[][] map; static int[][] dist; public static void main(String[] args) throws IOException { BufferedReader bf = new BufferedReader(new InputStreamReader(System.in)); int size = Integer.parseInt(bf.readLine()); map = new String[size][size]; dist = new int[size][size]; for (int i = 0; i < size; i++) { StringTokenizer st = new StringTokenizer(bf.readLine()); for (int j = 0; j < size; j++) { map[i][j] = st.nextToken(); dist[i][j] = Integer.MIN_VALUE; } } dist[0][0] = Integer.parseInt(map[0][0]); PriorityQueue<Dot> pq = new PriorityQueue<>((a, b) -> -(a.value - b.value)); pq.add(new Dot(0, 0, Integer.parseInt(map[0][0]))); while (!pq.isEmpty()) { Dot dot = pq.poll(); if (dot.x + 2 < map.length) { if (dist[dot.x + 2][dot.y] < cal(dist[dot.x][dot.y], Integer.parseInt(map[dot.x + 2][dot.y]), map[dot.x + 1][dot.y])) { dist[dot.x + 2][dot.y] = +cal(dist[dot.x][dot.y], Integer.parseInt(map[dot.x + 2][dot.y]), map[dot.x + 1][dot.y]); pq.add(new Dot(dot.x + 2, dot.y, Integer.parseInt(map[dot.x + 2][dot.y]))); } } if (dot.y + 2 < map.length) { if (dist[dot.x][dot.y + 2] < cal(dist[dot.x][dot.y], Integer.parseInt(map[dot.x][dot.y + 2]), map[dot.x][dot.y + 1])) { dist[dot.x][dot.y + 2] = cal(dist[dot.x][dot.y], Integer.parseInt(map[dot.x][dot.y + 2]), map[dot.x][dot.y + 1]); pq.add(new Dot(dot.x, dot.y + 2, Integer.parseInt(map[dot.x][dot.y + 2]))); } } if (dot.x + 1 < map.length && dot.y + 1 < map.length) { if (dist[dot.x + 1][dot.y + 1] < cal(dist[dot.x][dot.y], Integer.parseInt(map[dot.x + 1][dot.y + 1]), map[dot.x + 1][dot.y])) { dist[dot.x + 1][dot.y + 1] = cal(dist[dot.x][dot.y], Integer.parseInt(map[dot.x + 1][dot.y + 1]), map[dot.x + 1][dot.y]); pq.add(new Dot(dot.x + 1, dot.y + 1, Integer.parseInt(map[dot.x + 1][dot.y + 1]))); } if (dist[dot.x + 1][dot.y + 1] < cal(dist[dot.x][dot.y], Integer.parseInt(map[dot.x + 1][dot.y + 1]), map[dot.x][dot.y + 1])) { dist[dot.x + 1][dot.y + 1] = cal(dist[dot.x][dot.y], Integer.parseInt(map[dot.x + 1][dot.y + 1]), map[dot.x][dot.y + 1]); pq.add(new Dot(dot.x + 1, dot.y + 1, Integer.parseInt(map[dot.x + 1][dot.y + 1]))); } } } System.out.print(dist[dist.length - 1][dist.length - 1]+" "); for (int i = 0; i < size; i++) { for (int j = 0; j < size; j++) { dist[i][j] = Integer.MAX_VALUE; } } dist[0][0] = Integer.parseInt(map[0][0]); pq = new PriorityQueue<>((a, b) -> a.value - b.value); pq.add(new Dot(0, 0, Integer.parseInt(map[0][0]))); while (!pq.isEmpty()) { Dot dot = pq.poll(); if (dot.x + 2 < map.length) { if (dist[dot.x + 2][dot.y] > cal(dist[dot.x][dot.y], Integer.parseInt(map[dot.x + 2][dot.y]), map[dot.x + 1][dot.y])) { dist[dot.x + 2][dot.y] = +cal(dist[dot.x][dot.y], Integer.parseInt(map[dot.x + 2][dot.y]), map[dot.x + 1][dot.y]); pq.add(new Dot(dot.x + 2, dot.y, Integer.parseInt(map[dot.x + 2][dot.y]))); } } if (dot.y + 2 < map.length) { if (dist[dot.x][dot.y + 2] > cal(dist[dot.x][dot.y], Integer.parseInt(map[dot.x][dot.y + 2]), map[dot.x][dot.y + 1])) { dist[dot.x][dot.y + 2] = cal(dist[dot.x][dot.y], Integer.parseInt(map[dot.x][dot.y + 2]), map[dot.x][dot.y + 1]); pq.add(new Dot(dot.x, dot.y + 2, Integer.parseInt(map[dot.x][dot.y + 2]))); } } if (dot.x + 1 < map.length && dot.y + 1 < map.length) { if (dist[dot.x + 1][dot.y + 1] > cal(dist[dot.x][dot.y], Integer.parseInt(map[dot.x + 1][dot.y + 1]), map[dot.x + 1][dot.y])) { dist[dot.x + 1][dot.y + 1] = cal(dist[dot.x][dot.y], Integer.parseInt(map[dot.x + 1][dot.y + 1]), map[dot.x + 1][dot.y]); pq.add(new Dot(dot.x + 1, dot.y + 1, Integer.parseInt(map[dot.x + 1][dot.y + 1]))); } if (dist[dot.x + 1][dot.y + 1] > cal(dist[dot.x][dot.y], Integer.parseInt(map[dot.x + 1][dot.y + 1]), map[dot.x][dot.y + 1])) { dist[dot.x + 1][dot.y + 1] = cal(dist[dot.x][dot.y], Integer.parseInt(map[dot.x + 1][dot.y + 1]), map[dot.x][dot.y + 1]); pq.add(new Dot(dot.x + 1, dot.y + 1, Integer.parseInt(map[dot.x + 1][dot.y + 1]))); } } } System.out.print(dist[dist.length - 1][dist.length - 1]); } static int cal(int a, int b, String oper) { if (oper.equals("+")) { return a + b; } else if (oper.equals("-")) { return a - b; } else if (oper.equals("*")) { return a * b; } return 0; } static class Dot { int x; int y; int value; public Dot(int y, int x, int value) { this.x = x; this.y = y; this.value = value; } } }
댓글을 작성하려면
로그인
해야 합니다.
dlcksdnd321 4년 전
반례 부탁드립니다 ㅠㅠ
위에 나와있는 2가지는 맞았습니다