회원가입
로그인
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
문제집
대회
2
채점 현황
랭킹
게시판
그룹
더 보기
재채점 기록
블로그
강의
실험실
도움말
BOJ Stack
BOJ Book
전체
공지
자유
질문
오타/오역/요청
게시판 공지
홍보
업데이트
solved.ac
글쓰기
질문 도움말
자주묻는 질문
런타임에러의 원인을 모르겠습니다..
17144번 - 미세먼지 안녕!
rangsuk
4년 전
0
샘플케이스들 답은 다 잘나오는데
제출하면 채점시작하자마자 런타임에러가 뜹니다..
어디가 문제일까요 ㅠ ㅁ ㅠ
import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.IOException; import java.io.InputStreamReader; import java.io.OutputStreamWriter; import java.util.LinkedList; import java.util.Queue; import java.util.StringTokenizer; /* * 미세먼지는 각 자리에서 확산하는데 * 인접한 네방향으로 확산함 * 확산량 : Arc/5 * Arc에 남는 미세먼지의 양은 확산량x확산된 방향 개수 7 8 0 0 0 0 0 0 0 0 9 0 0 0 0 3 0 0 8 -1 0 5 0 0 0 22 0 -1 8 0 0 0 0 0 0 0 0 0 0 0 10 43 0 0 0 5 0 15 0 0 0 0 0 40 0 0 0 20 0 */ public class Main { static BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); static BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out)); static StringTokenizer st; static int R,C,T; static int remainDust=0; static int[][] room; static int[][] spreadAmountMap; static int cleanerR1,cleanerC1; static int cleanerR2,cleanerC2; static int[] dr = {-1,0,1,0}; static int[] dc = {0,1,0,-1}; static Queue<Dust> q; static public class Dust{ int row; int col; int amount; public Dust(int row, int col, int amount) { super(); this.row = row; this.col = col; this.amount = amount; } public static void main(String[] args) throws IOException { setData(); spreadSimulation(); countDust(); System.out.println(remainDust); } private static void spreadSimulation() { int time=0; while(!q.isEmpty()){ if(time==T) return; spreadAmountMap = new int[R][C]; time++; int size = q.size(); for(int i=0;i<size;i++){//먼지 하나씩 뺸다. Dust currentDust = q.poll(); int adjCnt=0; int spreadAmount = currentDust.amount/5; for(int dir=0;dir<4;dir++){ int nr = currentDust.row+dr[dir]; int nc = currentDust.col+dc[dir]; if(rangeCheck(nr,nc)){//영역 만족 if(room[nr][nc]!=-1) { adjCnt++; spreadAmountMap[nr][nc]+=spreadAmount; } } } spreadAmountMap[currentDust.row][currentDust.col]-=(spreadAmount*adjCnt); } setDust(); cleaner(); insertDustToQueue(); } } private static void insertDustToQueue() { for(int row=0;row<R;row++) { for(int col=0;col<C;col++) { if(room[row][col]>0) q.add(new Dust(row,col,room[row][col])); } } } private static void cleaner(){ //cleaner1 for(int row=cleanerR1-1;row>0;row--) room[row][0]= room[row-1][0]; for(int col=0;col<(C-1);col++) room[0][col] = room[0][col+1]; for(int row=0;row<cleanerR1;row++) room[row][C-1] = room[row+1][C-1]; for(int col=C-1;col>1;col--) room[cleanerR1][col]= room[cleanerR1][col-1]; room[cleanerR1][1]=0; //cleaner2 for(int row=cleanerR2+1;row<(R-1);row++) room[row][0]= room[row+1][0]; for(int col=0;col<(C-1);col++) room[R-1][col] = room[R-1][col+1]; for(int row=(R-1);row>cleanerR2;row--) room[row][C-1] = room[row-1][C-1]; for(int col=C-1;col>1;col--) room[cleanerR2][col]= room[cleanerR2][col-1]; room[cleanerR2][1]=0; } private static void setDust() { for(int row=0;row<R;row++) { for(int col=0;col<C;col++){ room[row][col]+=spreadAmountMap[row][col]; } } } private static boolean rangeCheck(int nr, int nc) { if(nr>=0 && nr<R && nc>=0 && nc <C) return true; return false; } private static void countDust() { for(int row=0;row<R;row++) { for(int col=0;col<C;col++) { if(room[row][col]>0) remainDust+=room[row][col]; } } } private static void setData() throws IOException { st = new StringTokenizer(br.readLine()); R = Integer.parseInt(st.nextToken()); C = Integer.parseInt(st.nextToken()); T = Integer.parseInt(st.nextToken()); room = new int[R][C]; q = new LinkedList<Dust>(); boolean firstCleaner = false; for(int row=0;row<R;row++) { st = new StringTokenizer(br.readLine()); for(int col=0;col<C;col++) { room[row][col] = Integer.parseInt(st.nextToken()); if(room[row][col]>0) q.add(new Dust(row, col, room[row][col])); if(room[row][col]==-1 && firstCleaner==false) { cleanerR1 = row; cleanerC1 = col; firstCleaner = true; }else if(room[row][col]==-1 && firstCleaner==true){ cleanerR2 = row; cleanerC2 = col; } } } } } }
댓글을 작성하려면
로그인
해야 합니다.
rangsuk 4년 전
샘플케이스들 답은 다 잘나오는데
제출하면 채점시작하자마자 런타임에러가 뜹니다..
어디가 문제일까요 ㅠ ㅁ ㅠ