PICNIC 문제 런타임 오류.,..

  • yoonsdaddy
    yoonsdaddy

    위 문제에 대한 C++ 답안을 Java로 변환해서 제출했는데 런타임오류 (RTE (nonzero return code)) 가 발생합니다. 뭐가 문제일까요?

    import java.util.Arrays;
    import java.util.Scanner;

    class Solution {
    static int AnswerN;

    static int n, m;
    static boolean areFriends[][] = new boolean[10][10];
    
    static int countPairings(boolean taken[]) {
        // 남은 학생들 중 가장 번호가 빠른 학생을 찾는다
        int firstFree = -1;
        for(int i = 0; i < (n); i++) {
            if(!taken[i]) {
                firstFree = i;
                break;
            }
        }
        // 기저 사례: 모든 학생이 짝을 찾았으면 한 가지 방법을 찾았으니 종료한다.
        if(firstFree == -1) return 1;
        int ret = 0;
        for(int pairWith = (firstFree+1); pairWith < (n); pairWith++) {
            if(!taken[pairWith] && areFriends[firstFree][pairWith]) {
                taken[firstFree] = taken[pairWith] = true;
                ret += countPairings(taken);
                taken[firstFree] = taken[pairWith] = false;
            }
        }
        return ret;
    }
    
    public static void main (String args[]) {
        Scanner sc = new Scanner(System.in);
    
        int k = sc.nextInt();
    
        for(int test_case = 1; test_case <= k; test_case++) {
            AnswerN = 0;    // AnswerN 초기화를 위해 새로 추가한 구문.
    
            n = sc.nextInt();
            m = sc.nextInt();
    
            for (int i = 0; i < n; ++i) {
                Arrays.fill(areFriends[i], false);              
            }
    
            for(int i = 0; i < (m); i++) {
                int a, b;
    
                a = sc.nextInt();
                b = sc.nextInt();
    
                areFriends[a][b] = areFriends[b][a] = true;
            }
    
            boolean taken[] = new boolean[10];
    
            AnswerN = countPairings(taken);
    
            // 표준출력(화면)으로 답안을 출력합니다.
            System.out.println(AnswerN);            
    
        }               
    
        sc.close();
    
    }

    }


    6년 전
1개의 댓글이 있습니다.
  • yoonsdaddy
    yoonsdaddy

    (자문자답) 아... class 명을 무조건 Main 으로 해야하는 거였네요...


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