[gcj] Re: ESAb ATAd problem was working in local.

2020-04-10 Thread Matt Fenlon
The name of your class should be Solution rather than Database. Check out 
the Coding section in the FAQ here: 
https://codingcompetitions.withgoogle.com/codejam/faq

On Tuesday, April 7, 2020 at 11:55:21 AM UTC-4, Aditya Gupta wrote:
>
> Following is my solution to it. I tested it extensively and it was working 
> on local. Maybe the interaction part was not working properly. Can anyone 
> please help me with what I did wrong?
>
>
> import java.io.BufferedReader;
> import java.io.InputStreamReader;
> import java.util.AbstractMap;
> import java.util.Objects;
> import java.util.Scanner;
>
> public class Database {
>
> private static AbstractMap.SimpleEntry sameBit;
> private static AbstractMap.SimpleEntry differentBit;
> private static Integer[] bits;
>
> public static void main(String[] args) {
> Scanner sc = new Scanner(new BufferedReader(new 
> InputStreamReader(System.in)));
> int numTestCases = sc.nextInt();
> for (int count = 0; count < numTestCases; count++) {
> int numBits = sc.nextInt();
> bits = new Integer[numBits];
> int numQueries = 0;
> int currentIndex = 0;
> while (currentIndex < numBits / 2) {
> if (numQueries > 0 && numQueries % 10 == 0) {
> getPreviousState();
> int changedSameBit = getBit(sc, sameBit.getKey());
> int changedDifferentBit = getBit(sc, 
> differentBit.getKey());
> performAppropriateAction(changedSameBit, 
> changedDifferentBit);
> } else {
> getBits(sc, currentIndex++);
> }
> numQueries += 2;
> }
> String result = "";
> for (Integer bit : bits) {
> result = result.concat(String.valueOf(bit));
> }
> System.out.println(result);
> String outcome = sc.next();
> if (outcome.equals("N")) {
> break;
> }
> System.exit(0);
> }
> }
>
> private static void performAppropriateAction(int changedSameBit, int 
> changedDifferentBit) {
> if (sameBit.getValue().equals(changedSameBit) && 
> !differentBit.getValue().equals(changedDifferentBit)) {
> performAction(ACTION.REVERSE);
> } else {
> if (differentBit.getValue().equals(changedDifferentBit)) {
> performAction(ACTION.REVERSE_COMPLEMENT);
> } else {
> performAction(ACTION.COMPLEMENT);
> }
> }
> }
>
> private static void getBits(Scanner sc, int index) {
> bits[index] = getBit(sc, index);
> bits[bits.length - 1 - index] = getBit(sc, bits.length - 1 - 
> index);
> }
>
> private static int getBit(Scanner sc, int index) {
> System.out.println(index + 1);
> sc.hasNext();
> return sc.nextInt();
> }
>
> private static void performAction(ACTION action) {
> switch (action) {
> case REVERSE:
> performReverseAction();
> break;
> case COMPLEMENT:
> performComplementAction();
> break;
> case REVERSE_COMPLEMENT:
> performReverseAction();
> performComplementAction();
> break;
> }
> }
>
> private static void performReverseAction() {
> int temp;
> for (int i = 0; i < bits.length / 2; i++) {
> if (Objects.nonNull(bits[i])) {
> temp = bits[i];
> bits[i] = bits[bits.length - 1 - i];
> bits[bits.length - 1 - i] = temp;
> } else {
> break;
> }
> }
> }
>
> private static void performComplementAction() {
> for (int i = 0; i < bits.length; i++) {
> if (Objects.nonNull(bits[i])) {
> if (bits[i] == 1) {
> bits[i] = 0;
> } else {
> bits[i] = 1;
> }
> }
> }
> }
>
> private static void getPreviousState() {
> if (Objects.nonNull(sameBit) && Objects.nonNull(differentBit)) {
> return;
> }
> for (int i = 0; i < bits.length / 2 && Objects.nonNull(bits[i]); 
> i++) {
> if (bits[i].equals(bits[bits.length - 1 - i])) {
> sameBit = new AbstractMap.SimpleEntry<>(i, bits[i]);
> } else {
> differentBit = new AbstractMap.SimpleEntry<>(i, bits[i]);
> }
> if (Objects.nonNull(sameBit) && Objects.nonNull(differentBit)) 
> {
> break;
> }
> }
> }
>
> enum ACTION {
> REVERSE, COMPLEMENT, REVERSE_COMPLEMENT;
> }
>
> }
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Google Code 

Re: [gcj] Debugging Interactive Problems

2020-04-10 Thread mattfenlon2
The interactive runner links stdin and stdout but does not touch stderr. I had 
success printing to stderr throughout your program to print useful, readable 
information.

> On Apr 10, 2020, at 6:55 PM, Lev Raizman  wrote:
> 
> 
> Hello all,
> 
> I'm looking for a method for debugging my solutions to interactive problems 
> using a debugger. In particular, I wan't to be able to set breakpoints in my 
> C++ solution, and have them trigger when it reaches that point. The problem 
> arises because I call the interactive runner, and pass the binary as a 
> parameter. I've spent quite sometime looking online, and couldn't find 
> anything relevant. It would also be nice if I could set breakpoints in the 
> local_test file, but that is optional.
> 
> I'm using Visual Studio Code, but a solution in any IDE, or even in gdb in a 
> terminal would be great.
> 
> Thank you,
> Lev
> -- 
> 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/0173995e-eb2c-4705-a5ab-41749910df13%40googlegroups.com.

-- 
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/A942A4A9-4C12-44EF-8940-1E31DD9FA1E2%40gmail.com.


[gcj] Debugging Interactive Problems

2020-04-10 Thread Lev Raizman
Hello all,

I'm looking for a method for debugging my solutions to interactive problems 
using a debugger. In particular, I wan't to be able to set breakpoints in 
my C++ solution, and have them trigger when it reaches that point. The 
problem arises because I call the interactive runner, and pass the binary 
as a parameter. I've spent quite sometime looking online, and couldn't find 
anything relevant. It would also be nice if I could set breakpoints in the 
local_test file, but that is optional.

I'm using Visual Studio Code, but a solution in any IDE, or even in gdb in 
a terminal would be great.

Thank you,
Lev

-- 
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/0173995e-eb2c-4705-a5ab-41749910df13%40googlegroups.com.


Re: [gcj] Re: Parenting Problem Returns more creative solution?

2020-04-10 Thread Nate Bauernfeind
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 > 
> 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> //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>  c[k] = 1;
>>  }
>> }
>> else if(!busyJ){
>> output+="J";
>> //fill J's schedule
>> for(int k=start; 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 .
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/google-code/354c7736-5258-4aad-8e14-cf870e185c9c%40googlegroups.com
>  
> 
> .
>
>

-- 
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.


[gcj] Re: [Python3] QR 2020 - Parenting Partnering Returns

2020-04-10 Thread porker2008


> Apparently "Case #3: CJJCC" is not a valid alternative for "Case #3: 
> JCCJJ".
>

I think CJJCC should also be accepted.
 

-- 
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/83e650d5-c13e-4363-b749-049e636e5941%40googlegroups.com.


[gcj] Re: Java: Parenting Partnering Returns WA

2020-04-10 Thread porker2008
Your solution simply does not work.

You need to process the activities based on their start time (or end time) 
instead of the order given in the input.

-- 
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/30a84eb9-1736-4739-a1e3-9b5dc394019e%40googlegroups.com.


[gcj] Re: [Python3] QR 2020 - Parenting Partnering Returns

2020-04-10 Thread eegee
Turns out that it *was not* a Runtime Error. Thanks to @porker2008 I was 
able to fix my answer by first sorting the activities. Apparently "Case #3: 
CJJCC" is not a valid alternative for "Case #3: JCCJJ".

On Tuesday, 7 April 2020 02:44:08 UTC+2, eegee wrote:
>
> I keep getting a RE (Runtime Error) for my solution on "Parenting 
> Partnering Returns". It passes the test case, but fails for the submission. 
> It is quite frustrating not knowing what the issue is. I spent an 
> inordinate amount of time trying to get the first solution submitted since 
> it also had RE that turned out to be a missing import statement.
>
> My proposed solution:
>
> def no_clash(person, activity_start, activity_end):
> for person_start, person_end in person:
> if activity_start < person_end < activity_end:
> return False
> if activity_start < person_start < activity_end:
> return False
> if activity_start <= person_start < person_end <= activity_end:
> return False
> if person_start <= activity_start < activity_end <= person_end:
> return False
> return True
>
>
> for case in range(int(input())):
> answer = ""
> cameron = []
> jamie = []
> for activity in range(int(input())):
> start, end = map(int, input().split())
> if no_clash(cameron, start, end):
> cameron.append((start, end))
> answer += "C"
> elif no_clash(jamie, start, end):
> jamie.append((start, end))
> answer += "J"
> else:
> answer = "IMPOSSIBLE"
> break
>
> print("Case #{}: {}".format(case + 1, answer))
>
>
> Test input:
>
> 4
> 3
> 360 480
> 420 540
> 600 660
> 3
> 0 1440
> 1 3
> 2 4
> 5
> 99 150
> 1 100
> 100 301
> 2 5
> 150 250
> 2
> 0 720
> 720 1440
>
>

-- 
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/5b4211a9-60f0-4cea-972b-6df2a0b41372%40googlegroups.com.


[gcj] Re: Vestigium C++ code giving Sample Failed:WA error

2020-04-10 Thread porker2008
Not sure why you need to call *cin.sync()* in your code.
You shouldn't do that because everything you haven't read from *STDIN* will 
be lost at that point.

-- 
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/280463e1-6f0f-4bed-a6b3-4ac645590ecb%40googlegroups.com.


[gcj] Re: Problem with 'printf' in ESAb ATAd (Interactive problem)

2020-04-10 Thread porker2008
How do interactive problems work?

Just as in non-interactive problems, you will receive input from stdin and 
print output to stdout. Our system will do the job of directing your output 
stream to the judge's input stream, and pointing the judge's output stream 
to your input stream. However, every time you output data, *you must flush 
your output buffer*, as explained below.

---

The reason why it is not working with *printf*, is because *STDOUT* is a 
buffered stream and it doesn't get flushed until the buffer is full or you 
manually triggered a flush.
Without flushing the stream, the other program will not receive your data 
and therefore cannot send more data to your program.
And your program wants to read the response and hence causes a deadlock.

It was like your postman is holding your mail and waiting for more mail to 
come in (because he wants to send all mails in a batch) and you are waiting 
for the response that never comes.

To solve this, simply flush your stream (like asking your postman to 
deliver your mail without waiting for more mails)

The reason why *cout* would work is because whenever a *std::endl* is sent 
to the stream, it also triggered a flush so you don't have to manually do 
that.
In other word, the following code will also fail for the same reason.

*cout << something << '\n';*

-- 
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/1efcb358-48a8-4939-9380-ff2327b3d1c2%40googlegroups.com.


Re: [gcj] Re: Parenting Partnering Returns

2020-04-10 Thread Edward Lockhart
The greedy approach you're using doesn't handle all cases, eg

0 1
5 6
0 2
1 6


On Fri, 10 Apr 2020, 16:55 rajeswara reddy, 
wrote:

>
> Can anyone find what's wrong in my program for parenting partners returns
> problem
>
> z=int(input())
> for zz in range(1,z+1):
> n=int(input())
> l=[]
> out='C'
> for i in range(n):
> t=list(map(int,input().split()))
> l.append(t)
> c=set(range(l[0][0],l[0][1]))
> j=set()
> for i in l[1:]:
> t=set(range(i[0],i[1]))
> if len(c.intersection(t))==0:
> out+='C'
> c.update(t)
> elif len(j.intersection(t))==0:
> out+='J'
> j.update(t)
> else:
> out="IMPOSSIBLE"
> break
> print("Case #{}: {}".format(zz,out))
>
>
>
>
>
> --
> 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/6a674140-a6c6-4074-8508-161566cea344%40googlegroups.com
> 
> .
>

-- 
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/CAE-ZSdL8C%2B0L-RrRSEUWWv5y%3DhQzosBNqvedrb0XqTK_CiBAxA%40mail.gmail.com.


[gcj] Link to Commented Solutions Archive

2020-04-10 Thread Matt Fenlon
I am maintaining an archive of C++ solutions for 2020 problems. Feel free 
to check out the link below if you have questions regarding a problem. Even 
if you are not using C++, reading through the comments may help you solve 
the problem in your preferred language. As time permits, I will be adding 
commented solutions of archived problems (2019 and before) from GCJ and 
Kickstart.

https://github.com/mfenlon/Google-Code-Jam-Archive-Solutions

-- 
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/d24e16fe-6101-4b36-9f44-e5da79224384%40googlegroups.com.


[gcj] Re: Parenting Partnering Returns

2020-04-10 Thread rajeswara reddy

Can anyone find what's wrong in my program for parenting partners returns 
problem

z=int(input())
for zz in range(1,z+1):
n=int(input())
l=[]
out='C'
for i in range(n):
t=list(map(int,input().split()))
l.append(t)
c=set(range(l[0][0],l[0][1]))
j=set()
for i in l[1:]:
t=set(range(i[0],i[1]))
if len(c.intersection(t))==0:
out+='C'
c.update(t)
elif len(j.intersection(t))==0:
out+='J'
j.update(t)
else:
out="IMPOSSIBLE"
break
print("Case #{}: {}".format(zz,out))





-- 
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/6a674140-a6c6-4074-8508-161566cea344%40googlegroups.com.


[gcj] Re: Parenting Partnering Returns

2020-04-10 Thread Pronoy Mandal
I will explain the algorithm step wise if someone wants to know the same 
and at the same tome tell about the edge cases one can miss. Following is 
the logic

1. Sort the input in ascending order of start times
2. Assign (0,0) as the end time of jobs allocated to Cameron and Jamie. 
They are o because they are initially not allocated anything.
3. Pick the first job from the sorted input. If the *end time is lesser 
than the start time* for Cameron i.e. Cameron is still busy and can't be 
allocated the job. Do the same check for Jamie. Even if she is busy then 
declare it as "IMPOSSIBLE" and break out of the loop.
4. Iterate through the entire sorted input until all allocations have been 
made or the scheduling has been declared impossible.
5. Return the allocations in the same order as the input.

Now time to explain the implementation in Python 3. We know that somehow we 
need to remember the order of the input. How would you do that?? Maybe a 
dictionary will work with the job (start,end) as the key and the value as 
'C' or 'J' (Initially you can mark it as 'X' or any other suitable 
character). Now while sorting the input you need to sort the keys only and 
carry out the above procedure. At the end you decide OK now the values of 
the keys have been updated correctly so there is nothing remaining you will 
simply concatenate the values using *''.join(D.values())*. As soon as you 
submit it, it gives you *WA*. 

Well, you say what is wrong? you did the allocation perfectly well the 
issue is with Python dictionaries. They are non-deterministic in terms of 
their order i.e. *the order of elements may change during run time or 
compile time* and that is why they may not maintain the order with which 
the input was given. The best way to get out of this is to use the same 
dictionary and keep a list initialized with all 0s or some other relevant 
character using ['X']*N and whenever you enumerate the job (or the key in 
this case) just simply place your allocation ('C' or 'J') at the index of 
the list which is equal to the value of the key. At the end simply use* 
''.join(L)* to  get the final answer. Now you run the tests in the problem 
and you realise that the eg. is working fine and you will never get a *WA* or 
*Sample Failed* and you submit your attempt to get the full bounty. Well... 
now you end up with an *RE(Run time Error)*. You are frustrated...what 
could go wrong now?

Well, there remains exactly one case that is creating the problem that is 
*intervals 
which are exactly the same*. For e.g. (2,7) and (2,7), the expected answer 
is 'CJ' or 'JC' because by definition they still overlap doesn't matter 
whether its a full, partial or exact overlap. Why was this creating an 
issue? In our dictionary the jobs were our keys. Encountering exactly the 
same interval will simply update the value of the key and not create a new 
key in the dictionary because all keys in a dictionary are unique. So, the 
value corresponding to (2,7) is the latest index it was encountered, say 3 
(although it was encountered at index 1 also). Now when enumerating through 
the sorted keys, the list is constantly getting updated with 'C' or 'J' at 
various positions except at *1* because no key has a value equal to *1*. At 
the end you again use the join() function but at index 1 you are either 
having some non string datatype such as 0 or an irrelevant character say 
'X' which never got updated and is available in the final answer. Depending 
on its datatype its either an *RE* or *WA*. 

So again the dictionaries are creating an issue. So let us abandon the use 
of dictionaries altogether. Simply create tuples of the form 
(start,end,index) and append the same to an empty list while taking the 
input. Sort the input and carry out the above procedure. Whenever you need 
to do an allocation use the empty list [0]*N as declared/initialised before 
and put your allocations at appropriate indices as done before depending on 
the last value of the job tuple. And now simply use the join() function to 
print out the final answer. All your prayers will be heard and you will be 
ridden of your *insanity* as soon as you see those two green ticks.

Here is my complete solution in Python3 for reference.

T = int(input())
for i in range(1,T+1):
N=int(input())
jobs=[]
for x in range(N):
jobs.append(tuple(map(int, input().split(' ')))+(x,))

L = [0]*N
cj=[0,0]
m = sorted(jobs)
imp = False
for j in m:
if j[0] >= cj[0]:
L[j[2]] = 'C'
cj[0] = j[1]
elif j[0] >= cj[1]:
L[j[2]] = 'J'
cj[1] = j[1]
else:
imp = True
break

if imp==True:
print("Case #{}: IMPOSSIBLE".format(i))
else:
print("Case #{}: {}".format(i,''.join(L)))


Hope this helps!!!



On Tuesday, April 7, 2020 at 6:20:28 AM UTC+5:30, Martin Seeler wrote:
>
> I'm asking to keep my sanity: Did anyone solve this problem 

[gcj] Re: Parenting Partnering Returns

2020-04-10 Thread Saurabh Gattani
C++ solution passing all test cases with detailed explanation here:- 
https://www.golibrary.co/google-codejam-2020-parenting-partnering-returns-solution/


Thanks,
Saurabh

On Tuesday, 7 April 2020 10:50:28 UTC+10, Martin Seeler wrote:
>
> I'm asking to keep my sanity: Did anyone solve this problem with Python?
> I can't find these tricky edge cases where my code fails, all variations I 
> try on my machine seem to work just fine. Still CodeJam Environment says 
> *WA*. 
>
> If there is someone who solved it in python, then I know I'm missing some 
> cases. Otherwise I start to question the environment :D
>
> Thanks and have a nice day everyone
>

-- 
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/001862c7-2002-442a-b82a-5ba41af25f84%40googlegroups.com.


[gcj] Java: Parenting Partnering Returns WA

2020-04-10 Thread Nuria Ruiz
Hi, I'm trying to resolve Parenting Partnering Returns, but I'm getting WA. 

The problem is that for me the results are OK.

My idea to solve that is to create a class named Activity and override the 
method equals, in the method equals I will check if the activity A 
intersects with activity B.

For me, an activity A intersects with another activity B if the initial 
hour of A is less than the final hour of B, and the final hour of A is 
greater than the initial hour of B.

Then what I do is:

   - Read the activity
   - If the list of activities of C is compatible with the new activity or 
   C does not have activities yet => add the activity to C
   - Else if the list of activities of J is compatible with the new 
   activity of J does not have activities yet => add the activity to J
   - Else is IMPOSSIBLE.

Some suggestion?

https://github.com/nuriaruiz/codejam.git

package ParentingPartneringReturns;


import java.io.*;
import java.util.*;

public class Solution {
private static class Activity {
private Integer ini;
private Integer fin;

public Activity(Integer ini, Integer fin) {
this.ini = ini;
this.fin = fin;
}

@Override
public boolean equals(Object obj) {
if (obj == this) { return true; }
if (obj == null || obj.getClass() != this.getClass()) { return 
false; }
Activity actividad = (Activity) obj;
// another option: Math.max(this.ini, actividad.ini) < 
Math.min(this.fin, actividad.fin)
return this.ini < actividad.fin && this.fin > actividad.ini;
}

@Override
public String toString() {
return "Inicio: "+this.ini+" , Fin: "+this.fin;
}
}

public static void main(String[] args) {
Scanner myReader = new Scanner(new BufferedReader(new 
InputStreamReader(System.in)));

try {
String data = myReader.nextLine();
Integer numRows = Integer.parseInt(data);
List listCasesResults = new ArrayList<>();

for (int c = 0; c < numRows; c++) {
data = myReader.nextLine();
Integer numActividades = Integer.parseInt(data);

List listActividadesJ = new ArrayList<>();
List listActividadesC = new ArrayList<>();

String outputString = "Case #"+(c+1)+": ";
for (int iAct = 0; iActhttps://groups.google.com/d/msgid/google-code/50bbe2a5-1dd6-4ddc-8d95-ff69483e9560%40googlegroups.com.


[gcj] ESAb ATAd [Python Solved]

2020-04-10 Thread Joseandres Hinojoza
Hello everybody, I would like to share my solution with Python 3. Its 
pretty long code, but it passes the three cases. I dont know about you, but 
this problem was really challenging and took a lot of tries to get it right.
Basically first I check 2 pairs that Bits[x] == Bits[B-x] and 
Bits[y]!=Bits[y]
Then I always check Bits[x] and Bits[y] to know in which case I am and then 
the following 8 checks I use to check 4 bits in the right side and 4 in the 
left side, and then I covert and save the last 8 bits I asked for, to the 
case where Bits[x] == Bits[y] == 0
It also involves more cases, but that was the main idea. So here is my code
https://github.com/Ualabi/Google-Code-Jam-2020/blob/master/Qualification%20Round/4_ESab%20ATAd.py

I also did a program with the judge system emulated, just to check that my 
solution was right. It can solve until 110 bits without reach the 150 
queries limit
https://github.com/Ualabi/Google-Code-Jam-2020/blob/master/Qualification%20Round/Probes3.py

Finally, I would like to add that I didnt have to use "sys.stdout.flush()", 
somehow it worked out without it, does anyone know why is it needed?

-- 
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/f176e46f-1327-4ff5-9df9-fad9d6b83088%40googlegroups.com.


[gcj] Re: C++, Parenting Partnering Returns, Qualification Round 2020. Help to find out the cause for fault!!!

2020-04-10 Thread Saurabh Gattani
Solution with explanation for parenting partnering here:- 
https://www.golibrary.co/google-codejam-2020-parenting-partnering-returns-solution/?fbclid=IwAR2SJfghu5n0yU1eTueA8SjGZ9Gcc5yIGj6i-pLCV5l-DJR_YJIUuwQBam8




On Tuesday, 7 April 2020 10:45:39 UTC+10, Olena Lizina wrote:
>
> Hi all,
>
> I didn't pass the Qualification Round 2020 because stuck with Parenting 
> Partnering Returns.
> My solution passes the Sample test cases, but failed on the first Test Set.
>
> I wrote unit tests and tried different data sets to test my code, but the 
> Google System didn't accept it.
> Today I checked solutions of others. Found an interesting solution and 
> tried to find out what did I miss.
> Found nothing :-(
>
> Can anybody help my to find some corner cases that I missed?
> Please!
>
> #include 
> #include 
> #include 
>
> using namespace std;
>
> class Activity
> {
> public:
>Activity(const int startTime, const int endTime)
>   : m_startTime{startTime}
>   , m_endTime{endTime}
>{
>}
>
>bool overlaps(const Activity& other) const
>{
>   bool result {true};
>   if (m_startTime > other.m_startTime)
>   {
>  result = m_startTime < other.m_endTime;
>   }
>   else
>   {
>  result = other.m_startTime < m_endTime;
>   }
>   return result;
>}
>
>int m_startTime;
>int m_endTime;
> };
>
> class Schedule
> {
> public:
>void addActivity(const Activity& activity)
>{
>   m_activities.push_back(activity);
>}
>
>void sortActivities()
>{
>   std::sort(m_activities.begin(), m_activities.end(), [](Activity lhs, 
> Activity rhs)
> {
>return lhs.m_startTime < rhs.m_startTime;
> });
>}
>
>std::string getSchedule()
>{
>   std::string res;
>
>   std::vector Jamies;
>   std::vector Camerons;
>
>   for (size_t i = 0; i < m_activities.size(); ++i)
>   {
>  auto& currActivity = m_activities.at(i);
>  if (Jamies.cend() == std::find_if(Jamies.cbegin(), Jamies.cend(), 
> [](const Activity& activity)
>{
>   return activity.overlaps(
> currActivity);
>}))
>  {
> Jamies.push_back(currActivity);
> res += "J";
>  }
>  else if (Camerons.cend() == std::find_if(Camerons.cbegin(), 
> Camerons.cend(), [](const Activity& activity)
>   {
>  return activity.
> overlaps(currActivity);
>   }))
>  {
> Camerons.push_back(currActivity);
> res += "C";
>  }
>  else
>  {
> res = "IMPOSSIBLE";
> break;
>  }
>   }
>   return res;
>}
> private:
>std::vector m_activities;
> };
>
> void assert(const std::string& func, const bool validate)
> {
>if (validate)
>{
>   std::cout << func << ": OK" << std::endl;
>}
>else
>{
>   std::cout << func << ": NOK" << std::endl;
>}
> }
>
> void testActivity()
> {
>{
>   Activity lhs(0, 1);
>   Activity rhs(0, 1);
>   assert(__FUNCTION__, lhs.overlaps(rhs));
>   assert(__FUNCTION__, rhs.overlaps(lhs));
>}
>{
>   Activity lhs(0, 10);
>   Activity rhs(0, 1);
>   assert(__FUNCTION__, lhs.overlaps(rhs));
>   assert(__FUNCTION__, rhs.overlaps(lhs));
>}
>{
>   Activity lhs(0, 10);
>   Activity rhs(3, 10);
>   assert(__FUNCTION__, lhs.overlaps(rhs));
>   assert(__FUNCTION__, rhs.overlaps(lhs));
>}
>{
>   Activity lhs(0, 10);
>   Activity rhs(10, 15);
>   assert(__FUNCTION__, !lhs.overlaps(rhs));
>   assert(__FUNCTION__, !rhs.overlaps(lhs));
>}
>{
>   Activity lhs(0, 10);
>   Activity rhs(11, 15);
>   assert(__FUNCTION__, !lhs.overlaps(rhs));
>   assert(__FUNCTION__, !rhs.overlaps(lhs));
>}
>{
>   Activity lhs(15, 20);
>   Activity rhs(10, 15);
>   assert(__FUNCTION__, !lhs.overlaps(rhs));
>   assert(__FUNCTION__, !rhs.overlaps(lhs));
>}
> }
>
> void testSchedule()
> {
>{
>   Schedule today;
>   today.addActivity(Activity{360, 480});
>   today.addActivity(Activity{420, 540});
>   today.addActivity(Activity{600, 660});
>   assert(__FUNCTION__, (today.getSchedule() == "JCJ"));
>}
>{
>   Schedule today;
>   today.addActivity(Activity{0, 1440});
>   today.addActivity(Activity{1, 3});
>   today.addActivity(Activity{2, 4});
>   assert(__FUNCTION__, (today.getSchedule() == "IMPOSSIBLE"));
>}
>{
>   Schedule today;
>   today.addActivity(Activity{99, 150});
>   today.addActivity(Activity{1, 100});
>   today.addActivity(Activity{100, 301});
>   

[gcj] Problem with 'printf' in ESAb ATAd (Interactive problem)

2020-04-10 Thread Sairam Gaddam
Hi everyone,

I have some issue when testing the interactive problem ESAb ATAd with the 
provided testing tool.

I coded my solution in C and the testing tool doesn't run because of 
'printf'. It waits in infinite loop.
I ran my code separately and it works just fine.

To investigate this issue, I took a cpp solution for the same problem from 
here. 
https://codingcompetitions.withgoogle.com/codejam/submissions/0019fd27/RXJyaWNodG8

I replaced the cout in query() function with printf and testing tool 
doesn't seem to work(The program waits in an infinite loop).

I uploaded the cpp files(via pastebin links), one which works with testing 
tool provided and one which doesn't.
(*BOTH THE CODES ARE EXACTLY SAME EXCEPT FOR COUT AND PRINTF*)
Kindly help me why this problem occurs. Am I missing anything? Or something 
wrong with printf?

works.cpp 
doesnotwork.cpp 

Thank you,
Sai Ram

-- 
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/a62157df-759b-4cc6-8f82-429620e73175%40googlegroups.com.


[gcj] Re: Vestigium C++ code giving Sample Failed:WA error

2020-04-10 Thread Saimohan Kuncham
Here is the code in C++. 

Can you please clarify - When testing on local machine is it sufficient to 
enter inputs from keyboard. Or should the program run from redirected 
standard input and output. My program works when I enter input manually 
from keyboard. I am using cin for reading No of cases and N. For reading 
the matrix I use getline. If I do not make any changes and run by 
redirecting input and output

myprogram.exe < input > output

I do not get proper results.

---

#include 
#include 
#include 
#include 
#include 
#include 
using namespace std;
int main() {
  int C;
  cin >> C;
  for (int caseno = 1; caseno <= C; caseno++) {
int N; cin >> N;
int tracesum=0;   
string numbers;
int intnumbers;

vector rowsrepeat;
vector colsrepeat;
vector arrelementrowcount1;
vector  > arrelementrowcount2;
vector arrelementcolcount1;
vector  > arrelementcolcount2;
int rowsrepeatnum=0;
int colsrepeatnum=0;
for (int i=0; i  arrinput1;
vector  >  arrinput2;
for (int i=0; i> intnumbers) {
  arrinput1.push_back(intnumbers);  
}  
arrinput2.push_back(arrinput1);
} 
int i=0;int j=0;
for (auto it1 = arrinput2.begin(); it1 != arrinput2.end(); it1++) {
  j=0;
  for (auto it2 = (*it1).begin(); it2 != (*it1).end(); it2++ ) {
  int in = *it2;
if (arrelementrowcount2[i][in]) {  
  rowsrepeat[i] = true;  
}
arrelementrowcount2[i][in] = true;
if (arrelementcolcount2[j][in]) {  
  colsrepeat[j] = true;  
}
arrelementcolcount2[j][in] = true;
if (i==j) {
  tracesum = tracesum + in;
}
j++;  

  }
 i++; 
 
}  

for (int i=0; i
> When I run my code locally using MinGW compiler I am getting the right 
> answers. 
>
> I have tried the sample testcases given in the problem and they also give 
> the correct results when run locally. On the Code jam environment I am 
> getting wrong results both in test (where I manually enter the inputs)and 
> attempt when I run the program. 
>
> My program which compiles and runs without any errors should work at least 
> for the Sample testcases. What could be the problem ?
>
> Is there any specific name for the cpp file which I have to upload ? I 
> tried renaming to Solution.cc and then upload it but it did not help.
>
> Any help will be appreciated.
>
> Thanks
> Saimohan Kuncham
>

-- 
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/2f1dbc94-0255-486d-80b5-73bebcfaec37%40googlegroups.com.


[gcj] How to use Hall's Marriage Theorem to prove in Indicium

2020-04-10 Thread James Prudd
According to the analysis of Indicium problem in 
https://codingcompetitions.withgoogle.com/codejam/round/0019fd27/00209aa0

I wonder how to prove it. Can someone here write a detailed proof please? 
In particular, why greedily starting from the rows with B and C on their 
diagonal is the key here?

We can greedily pick any perfect matching for each row *starting with the 
rows with B and C on their diagonal*. Once we have filled in these two 
rows, we can use Hall's Marriage Theorem 
 to show that we 
will never run into any issues (so long as the conditions above about A, B, 
C are met). 

-- 
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/3b23cbf2-1e35-4790-b49a-e0a7e0ba954b%40googlegroups.com.


[gcj] Re: kick start 2020 round A: allocation problem Sample Failed: RE

2020-04-10 Thread porker2008
Your code does not run on my local dev machine
To be more specific, the following line throw a runtime exception
*A.sort()*

The exception message was like *AttributeError: 'map' object has no 
attribute 'sort'*

To fix this, you simply convert A to a list. See my code below.

*def solution():*
*N,B=map(int,input().split())*
*A=map(int,input().split())*
*A = list(A) # convert A to a list before calling sort*
*A.sort()*
*cout=0*
*for i in A:*
*if i<=B:*
*B-=i*
*cout+=1*
*return cout*

*T=int(input()) *
*for x in range(1,T+1):*
*print ("Case #{}: {}".format(x, solution()))*

-- 
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/3c99c4ce-cdcb-4bac-af74-f2488beeb9b6%40googlegroups.com.