java RTE 때문에 미치겠습니다 ㅠㅠ

  • koamania
    koamania

    https://algospot.com/judge/problem/read/DOLLS

    이 문제인데 자꾸
    non zero return code 에러가 뜨네요 ㅠㅠㅠㅠ
    뭐가 문제일까요...
    튜토리얼 읽어봐도 그닥 문제 없어보이는데...

    import java.util.ArrayList;
    import java.util.List;
    import java.util.ListIterator;
    import java.util.Scanner;
    
    public class Main {
        public static void main(String args[]) {
    
            try(Scanner sc = new Scanner(System.in)){
                int T = sc.nextInt();
                sc.nextLine();
                for(int i = 0 ; i < T ; i++){
    
                    int dollCount = sc.nextInt();
                    int donate = sc.nextInt();
    
                    sc.nextLine();
    
                    String data = sc.nextLine();
    
                    String[] splitedData = data.split(" ");
    
                    ArrayList<Integer> dolls = new ArrayList<Integer>(dollCount);
    
                    dolls.add(Integer.parseInt(splitedData[0]));
                    dolls.add(Integer.parseInt(splitedData[1]));
                    dolls.add(Integer.parseInt(splitedData[2]));
    
                    List<Integer> resultList = new ArrayList<Integer>(dollCount);
    
                    for(int temp = 0 ; temp < dollCount ; temp++) resultList.add(0);
    
    
                    int remain = donate;
                    while(true){
                        if(remain == 0) break;
                        if(dollCount > remain){
                            for(int j = 0, length = remain ; j < length ; j++){
                                if(j == dolls.size() || remain == 0) break;
                                if(dolls.get(j) == 0){
                                    length = length + 1;
                                }else{
                                    dolls.set(j, dolls.get(j) -1);
                                    resultList.set(j, resultList.get(j) + 1);
                                    remain = remain - 1;
                                }
                            }
                        }else{
                            for(int j = 0 ; j < dollCount ; j++){
                                if(dolls.get(j) != 0){
                                    dolls.set(j, dolls.get(j) -1);
                                    resultList.set(j, resultList.get(j) + 1);
                                    remain = remain - 1;
                                }
                            }
                        }
                        continue;
                    }
    
                    ListIterator<Integer> it = resultList.listIterator();
                    while(it.hasNext()){
                        System.out.print(it.next());
    
                        if(it.hasNext()){
                            System.out.print(" ");
                        }
                    }
                    if(i != T - 1) System.out.println();;
                }
            }
    
        }
    }
    

    7년 전
3개의 댓글이 있습니다.
  • koamania
    koamania

    이분검색을 우선 해봐야겠군요


    7년 전 link
  • KIMMINJAE
    KIMMINJAE

    저도 그렇습니다. 저도 제가 푼 문제들 다 모든예제를 랜덤으로 만드는 메소드까지 동원해서 풀어봐도 문제없이 잘나와도

    논제로리턴 ,,,ㅠㅠ 자꾸떠요,,, 미쳐붜려~


    7년 전 link
  • KIMMINJAE
    KIMMINJAE

    혹시 이유 알게되시면 저한테 쪽지보내주실 수 있을까요

    감사합니다


    7년 전 link
  • 정회원 권한이 있어야 커멘트를 다실 수 있습니다. 정회원이 되시려면 온라인 저지에서 5문제 이상을 푸시고, 가입 후 7일 이상이 지나셔야 합니다. 현재 문제를 푸셨습니다.