답안 #135912

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
135912 2019-07-24T13:29:03 Z model_code Who wants to live forever? (CERC12_B) Java 11
0 / 1
1000 ms 62080 KB
// CERC 2012
// Problem B: Who wants to live forever?
// O(n log n) solution
// Author: Lech Duraj

import java.util.Scanner;
import java.util.ArrayList;
public class B
{
  public static Boolean go(ArrayList<Integer> A)
  {
    int n = A.size();
    Boolean allzero = true;
    for(int i=0; i<n; i++)
      if (A.get(i)==1)
        allzero = false;
    if (allzero)
      return true;
    if (n==1)
      return true;
    if (n%2==0)
      return false;
    ArrayList<Integer> even = new ArrayList<Integer>();
    ArrayList<Integer> odd = new ArrayList<Integer>();
    for(int i=1; i<n; i+=2)
    {
      even.add(A.get(i));
      odd.add(A.get(i-1)^A.get(i+1));
    }
    return go(odd) && go(even);
  }

  public static void main(String args[])
  {
       Scanner in = new Scanner(System.in);
       int TT = in.nextInt();
       in.nextLine();
       while(TT>0)
       {
         TT--;
         String s = in.nextLine();
         int n = s.length();
         ArrayList<Integer> A = new ArrayList<Integer>();
         for(int i=0; i<n; i++)
           A.add(s.charAt(i)-'0');
         if (go(A))
           System.out.println("DIES");
         else
           System.out.println("LIVES");
       }
   }
}
# 결과 실행 시간 메모리 Grader output
1 Correct 126 ms 11708 KB Output is correct
2 Correct 128 ms 11048 KB Output is correct
3 Execution timed out 1274 ms 62080 KB Time limit exceeded
4 Halted 0 ms 0 KB -