Submission #341123

# Submission time Handle Problem Language Result Execution time Memory
341123 2020-12-29T03:22:20 Z sunshine_unicorn Carnival (CEOI14_carnival) Java 11
0 / 100
247 ms 13700 KB
import java.util.*;
import java.io.*;

public class carnival
{
   public static void main(String[] args) throws FileNotFoundException
   {
      // Scanner in = new Scanner(new File("carnival.in"));
      Scanner in = new Scanner(System.in);
      int n = in.nextInt();
      int[] prefix = new int[n + 1];
      int[] result = new int[n + 1];
      int total = 0;
      prefix[1] = 1;
      result[1] = 1;
      total++;
      
      for(int i = 2; i <= n; i++)
      {
         String s = print(1, i - 1);
         System.out.println(s + " " + i);
         int current = in.nextInt();
         if(current > prefix[i - 1])
         {
            prefix[i] = prefix[i - 1] + 1;
            total++;
            result[i] = total;
         }
         else
         {
            int color = result[binarySearch(in, i, current)];
            prefix[i] = prefix[i - 1];
            result[i] = color;
         }
         // System.out.println(Arrays.toString(result));
      }
      in.close();
      
      System.out.print("0 ");
      for(int i = 1; i <= n; i++)
      {
      // PrintWriter out = new PrintWriter(new File("carnival.out"));
         System.out.print(result[i] + " ");
      // out.println(result);
      // out.close();
      }
   }
   static int binarySearch(Scanner in, int i, int current)
   {
      int a = 1;
      int b = i - 1;
      while(a != b)
      {
         int mid = (a + b) / 2;
         
         String s1 = print(a, mid);
         System.out.println(s1);
         int count1a = in.nextInt();
         System.out.println(s1 + " " + i);
         int count1b = in.nextInt();
         
         String s2 = print(mid + 1, b);
         System.out.println(s2);
         int count2a = in.nextInt();
         System.out.println(s2 + " " + i);
         int count2b = in.nextInt();
         
         if(count1a == count1b)
            b = mid;
         else if(count2a == count2b)
            a = mid + 1;
      }  
      return a;
   }
   static String print(int a, int b)
   {
      String s = "";
      for(int i = a; i <= b; i++)
         s += i + " ";
      return s.trim();
   }
}
# Verdict Execution time Memory Grader output
1 Execution timed out 221 ms 13700 KB Time limit exceeded (wall clock)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 214 ms 12776 KB Time limit exceeded (wall clock)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 214 ms 12908 KB Time limit exceeded (wall clock)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 247 ms 13112 KB Time limit exceeded (wall clock)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 219 ms 12776 KB Time limit exceeded (wall clock)
2 Halted 0 ms 0 KB -