ZEROONE 문제에 대한 질문입니다.

  • 북극곰R
    북극곰R

    나름대로 정성 들여서 코드를 짜서 제출을 해보았는데 계속해서 시간 초과가 뜹니다..

    도대체 어떻게 코드를 짜야지 시간 초과 문제가 해결 될지 모르겠습니다..

    의견 부탁드립니다..

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

    위는 문제 링크이고

    아래는 코드 입니다..

    import java.util.Scanner;

    public class Main {
    public static void main(String[] args) {
    Scanner scan = new Scanner(System.in);
    String sequence = scan.nextLine();
    int round = scan.nextInt();
    String[][] startEnd = new String[round][2];
    String[] result = new String[round];
    int count = 0;
    for(int i = 0 ; i < round ; i++)
    {
    int a = Integer.parseInt(scan.next());
    int b = Integer.parseInt(scan.next());

    if(a>b)
            {
                int temp = a;
                a = b;
                b = temp;
            }
    
            int max = 0;
            int min = 0;
    
            String[] sequencePart = sequence.substring(a, b+1)
                                            .split("");
            for(String x : sequencePart)
            {
                if(x.equals("1"))
                {
                    max = 1;
                    count++;
    
                }
                if(count == sequencePart.length)
                    min = 1;
            }
            if(max==min)
                result[i] = "yes";
            else
                result[i] = "no";
    
        }
        for(String prt : result)
            System.out.println(prt);
    
    }

    }


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