The approach of greedy assigning out-of-order fails in this case:

J1: 0 2 (Assigns to C)
J2: 1 4 (Assigns to J)
J3: 8 10 (Assigns to C)
J4: 3 10 (Now Impossible because C is busy 8-10, and J is busy 3-4.)

However swapping J1 and J2 so that J is busy 0-2 and C is busy 1-4, now J 
is free to do task J4 3-10.

On Thursday, April 9, 2020 at 1:00:25 PM UTC-4, mattf...@gmail.com wrote:
>
> Hi Igor!
>
> Before I go in and debut your code, will you please explain the logic 
> behind your solution?
>
> On Apr 9, 2020, at 11:45 AM, Igor Cha <alenwa...@gmail.com <javascript:>> 
> wrote:
>
> 
> can anyone help out? D: 
>
> On Tuesday, April 7, 2020 at 8:51:58 AM UTC-7, Igor Cha wrote:
>>
>> Hi, I initially approached this using the same way as in the analysis of 
>> the problem, but I thought I found a better solution. However, it kept 
>> giving me WA and I am trying to figure out why. It passes all the examples 
>> successfully as far as I can tell. 
>>
>> Could someone please help me out? 
>>
>> Thanks. The code is below in java. 
>>
>> import java.util.*;
>> import java.io.*;
>> public class Solution {
>>     public static void main(String[] args) {
>>         Scanner in = new Scanner(new BufferedReader(new 
>> InputStreamReader(System.in)));
>>         int t = in.nextInt(); // Scanner has functions to read ints, 
>> longs, strings, chars, etc.
>>         for (int i = 1; i <= t; ++i) {
>>             int n = in.nextInt();
>>             //schedules for c and j false is free true is busy 0-1440
>>             int[] c = new int[1441];
>>             int[] j = new int[1441];
>>             boolean busyC = false;
>>             boolean busyJ = false;
>>             boolean impossibleFlag = false;
>>             int start = 0;
>>             int end = 0;
>>             String output = "";
>>             //go through n tasks to try and assign
>>             for(int x=1; x<=n; x++){
>>                 start = in.nextInt();
>>                 end = in.nextInt();
>>                 if(!impossibleFlag) {
>>                     for(int k=start; k<end; k++){
>>                         //check schedule for c and j
>>                         if(c[k]==1){
>>                             busyC = true;
>>                         }
>>                         if(j[k]==1){
>>                             busyJ = true;
>>                         }
>>                     }
>>                     if(!busyC){
>>                          output+="C";
>>                         //fill C's schedule
>>                          for(int k=start; k<end; k++){
>>                              c[k] = 1;
>>                          }
>>                     }
>>                     else if(!busyJ){
>>                         output+="J";
>>                         //fill J's schedule
>>                         for(int k=start; k<end; k++){
>>                             j[k] = 1;
>>                         }
>>                     }
>>                     else{
>>                         output="IMPOSSIBLE";
>>                         impossibleFlag = true;
>>                     }
>>                     busyC=false;
>>                     busyJ=false;
>>                 }
>>             }
>>             System.out.println("Case #" + i + ": " + output);
>>         }
>>     }
>> }
>>
>>
>> -- 
> You received this message because you are subscribed to the Google Groups 
> "Google Code Jam" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to googl...@googlegroups.com <javascript:>.
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/google-code/354c7736-5258-4aad-8e14-cf870e185c9c%40googlegroups.com
>  
> <https://groups.google.com/d/msgid/google-code/354c7736-5258-4aad-8e14-cf870e185c9c%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Google Code Jam" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to google-code+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/google-code/ea88c17e-1848-4c9e-9b19-3855f0678233%40googlegroups.com.

Reply via email to