회원가입
로그인
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
글쓰기
질문 도움말
자주묻는 질문
1%에서 안넘어갑니다. ㅠㅠ 도와주세요 모든 반례 통과했습니다.
17143번 - 낚시왕
rladudwns164
3년 전
0
시간만 날렸습니다. 도와주십셔 ㅠㅠ
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.lang.reflect.InaccessibleObjectException; import java.util.ArrayList; import java.util.Comparator; import java.util.List; import java.util.PriorityQueue; import java.util.StringTokenizer; import java.util.stream.Collectors; import java.util.stream.IntStream; public class Baek17143 { static int R, C, M; static int result; static int FishMan = -1; static int[] dx = {-1, 1, 0, 0}; static int[] dy = {0, 0, 1, -1}; // 상 하 우 좌 static List<Shark> sharks = new ArrayList<>(); public static void main(String[] args) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st = new StringTokenizer(br.readLine()); R = Integer.parseInt(st.nextToken()); C = Integer.parseInt(st.nextToken()); M = Integer.parseInt(st.nextToken()); for (int i = 0; i < M; i++) { st = new StringTokenizer(br.readLine()); int x = Integer.parseInt(st.nextToken()) - 1; int y = Integer.parseInt(st.nextToken()) - 1; int speed = Integer.parseInt(st.nextToken()); int direction = Integer.parseInt(st.nextToken()) - 1; int size = Integer.parseInt(st.nextToken()); sharks.add(new Shark(x, y, speed, direction, size)); } while (FishMan < C - 1) { Catch(); SharkMove(); EatSharks(); } System.out.println(result); } static void Catch() { FishMan++; List<Shark> sharkList = sharks.stream() .filter(shark -> FishMan == shark.y) .collect(Collectors.toList()); sharkList.sort(((o1, o2) -> o1.y - o2.y)); if (!sharkList.isEmpty()) { result += sharkList.get(0).size; sharks.remove(sharkList.get(0)); } } static void SharkMove() { for (Shark shark : sharks) { for (int i = 0; i < shark.speed; i++) { int nx = shark.x + dx[shark.direction]; int ny = shark.y + dy[shark.direction]; if (nx >= R || ny >= C || nx < 0 || ny < 0) { if (shark.direction == 0) { shark.direction = 1; } else if (shark.direction == 1) { shark.direction = 0; } else if (shark.direction == 2) { shark.direction = 3; } else if (shark.direction == 3) { shark.direction = 2; } nx = shark.x + dx[shark.direction]; ny = shark.y + dy[shark.direction]; } shark.x = nx; shark.y = ny; } } } static void EatSharks() { Shark[][] sharkMap = new Shark[R][C]; for (Shark now : sharks) { if (sharkMap[now.x][now.y] == null) { sharkMap[now.x][now.y] = now; } else if (sharkMap[now.x][now.y].size < now.size) { sharkMap[now.x][now.y] = now; } } List<Shark> surviveSharks = new ArrayList<>(); for (int i = 0; i < R; i++) { for (int j = 0; j < C; j++) { if (sharkMap[i][j] != null) { surviveSharks.add(sharkMap[i][j]); } } } sharks.clear(); sharks.addAll(surviveSharks); } } class Shark { int x; int y; int speed; int direction; int size; Shark(int x, int y, int speed, int direction, int size) { this.x = x; this.y = y; this.speed = speed; this.direction = direction; this.size = size; } }
댓글을 작성하려면
로그인
해야 합니다.
rladudwns164 3년 전
시간만 날렸습니다. 도와주십셔 ㅠㅠ