Submission #339700

# Submission time Handle Problem Language Result Execution time Memory
339700 2020-12-26T01:06:59 Z sunshine_unicorn Job Scheduling (CEOI12_jobs) Java 11
0 / 100
183 ms 12756 KB
import java.util.*;
import java.io.*;

class scheduling
//public class scheduling
{
   static String[] names;
   public static void main(String[] args) throws FileNotFoundException
   {
      // Scanner in = new Scanner(new File("scheduling.in"));
      Scanner in = new Scanner(System.in);
      int n = in.nextInt();
      int d = in.nextInt();
      int m = in.nextInt();
      Request[] array = new Request[m];
      for(int i = 0; i < m; i++)
         array[i] = new Request(i + 1, in.nextInt());
      in.close();
      
      Arrays.sort(array);
      names = new String[n];
      int result = binarySearch(n, d, m, array);
      works(n, d, m, array, result);
      
      // PrintWriter out = new PrintWriter(new File("scheduling.out"));
      System.out.println(result);
      // out.println(result);
      for(int i = 0; i < n; i++)
      {
         System.out.println(names[i] + "0");
         // out.println(names[i]);
      }
      // out.close();
   }
   static int binarySearch(int n, int d, int m, Request[] array)
   {
      int a = 1;
      int b = m;
      /*while(a != b)
      {
         int mid = (a + b) / 2;
         if(works(n, d, m, array, mid))
            b = mid;
         else
            a = mid + 1;
      }*/
      return a;
   }
   static boolean works(int n, int d, int m, Request[] array, int mid)
   {
      int[] assign = new int[m];
      for(int i = 1; i < m; i++)
         assign[i] = (assign[i - 1] + 1) % mid;
      int[] lastSeen = new int[mid];
      for(int i = 0; i < n; i++)
         names[i] = "";
      
      for(int i = 0; i < m; i++)
      {
         if(lastSeen[assign[i]] + 1 - array[i].day > d)
            return false;  
         if(array[i].day - lastSeen[assign[i]] > 0)
            lastSeen[assign[i]] = array[i].day;
         else
            lastSeen[assign[i]] = lastSeen[assign[i]] + 1;
         if(lastSeen[assign[i]] - 1 > n)
            return false;
         names[lastSeen[assign[i]] - 1] += array[i].index + " ";
      }
      return true;
   }
   static class Request implements Comparable<Request>
   {
      int index, day;
      Request(int index, int day)
      {
         this.index = index;
         this.day = day;
      }
      public int compareTo(Request other)
      {
         return this.day - other.day;
      }
      public String toString()
      {
         return index + ":" + day;
      }
   }
}
# Verdict Execution time Memory Grader output
1 Runtime error 179 ms 12756 KB Execution failed because the return code was nonzero
2 Runtime error 165 ms 12556 KB Execution failed because the return code was nonzero
3 Runtime error 183 ms 12504 KB Execution failed because the return code was nonzero
4 Runtime error 182 ms 12376 KB Execution failed because the return code was nonzero
5 Runtime error 165 ms 12396 KB Execution failed because the return code was nonzero
6 Runtime error 163 ms 12376 KB Execution failed because the return code was nonzero
7 Runtime error 171 ms 12504 KB Execution failed because the return code was nonzero
8 Runtime error 166 ms 12592 KB Execution failed because the return code was nonzero
9 Runtime error 163 ms 12420 KB Execution failed because the return code was nonzero
10 Runtime error 162 ms 12552 KB Execution failed because the return code was nonzero
11 Runtime error 166 ms 12376 KB Execution failed because the return code was nonzero
12 Runtime error 174 ms 12476 KB Execution failed because the return code was nonzero
13 Runtime error 167 ms 12376 KB Execution failed because the return code was nonzero
14 Runtime error 165 ms 12376 KB Execution failed because the return code was nonzero
15 Runtime error 166 ms 12296 KB Execution failed because the return code was nonzero
16 Runtime error 164 ms 12452 KB Execution failed because the return code was nonzero
17 Runtime error 162 ms 12384 KB Execution failed because the return code was nonzero
18 Runtime error 165 ms 12572 KB Execution failed because the return code was nonzero
19 Runtime error 164 ms 12376 KB Execution failed because the return code was nonzero
20 Runtime error 162 ms 12308 KB Execution failed because the return code was nonzero