CLOCK SYNC 질문 드립니다.

  • rainmaker007
    rainmaker007

    안녕하세요. 알고리즘에 흥미있어서 시작한 직장인입니다.

    문제 풀던 도중 궁금한 점이 있어 글을 올리게 되었습니다.

    로컬에서 돌릴 때는 잘돌아가는데 웹에 올릴 때 오답 처리가 나오고 있습니다.

    상당히 많은 테스트 케이스를 넣어봤는데 왜 오답이 나오는지를 모르겠습니다.

    답변 부탁드립니다. 감사합니다. 컴파일 에러나 런타임 오류 아닙니다.

    소스 첨부했습니다.

    import java.io.BufferedReader;
    import java.io.IOException;
    import java.io.InputStreamReader;
    import java.util.ArrayList;
    import java.util.List;

    public class CLOCKSYNC
    {
    private static final int switchNum = 10;
    private static int min = Integer.MAX_VALUE;

    static int watch[] = new int[16];
    static int [][] switchList = {{0,1,2}, {3,7,9,11}, {4, 10, 14, 15}, {0, 4, 5, 6, 7}, {6, 7, 8, 10, 12}, {0, 2, 14, 15}, {3, 14, 15}, {4, 5, 7, 14, 15}, {1, 2, 3, 4, 5}, {3, 4, 5, 9, 13}}; 
    static int [] tempWatch; 
    
    public static void main(String[] args) throws IOException 
    {
        List<Integer> picked = new ArrayList<Integer>();
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer st = null;
        int cNum = Integer.parseInt(br.readLine().trim());
        for (int i = 0; i < cNum; i++) {
            st = new StringTokenizer(br.readLine().trim(), " ");
            for (int j = 0 ; j < 16 ; j++)
                watch[j] = Integer.parseInt(st.nextToken());
            tempWatch = watch.clone();
            solve(picked);
            if (min == Integer.MAX_VALUE) System.out.println(-1);
            else System.out.println(min);
            min = Integer.MAX_VALUE; tempWatch = watch.clone();
        }
        br.close();
    }
    
    public static void solve(List<Integer> picked)
    {
        if (picked.size() == switchNum)
        {
            int tempMin = 0;
    
            for (int i = 0 ; i < picked.size() ; i++)
            {
                tempMin += picked.get(i);
                for (int j = 0 ; j < switchList[i].length ; j++)
                {
                    tempWatch[switchList[i][j]] += 3 * picked.get(i);
                }
            }
    
            for (int i = 0 ; i < tempWatch.length ; i++)
            {
                if (tempWatch[i] % 12 != 0)
                    return ;
            }
    
            min = Math.min(min, tempMin);
    
            return ;
        }
    
    
        for (int next = 0 ; next < 4 ; next++)
        {
            picked.add(next);
            solve(picked);
            picked.remove(picked.size() - 1);
        }
    }

    }


    8년 전
1개의 댓글이 있습니다.
  • rainmaker007
    rainmaker007

    if (tempWatch[i] % 12 != 0)
    return ;

    이 부분이 초기화가 안되있었네요...
    tempWatch = watch.clone() 넣어서 해결했습니다.


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