Re: [gcj] Running interactive problems with JAVA

2019-05-01 Thread 'Pablo Heiber' via Google Code Jam
You should replace "./mybinary" with the command for running your solution.
If your solution is java, the proper line is probably something like:

"python interactive_runner.py python testing_tool.py 0 -- java Solution"

Although that depends on your local java installation and your preferences
for usage. You can add flags to the "java" invocation if you use them
locally, for example. And if the language is a compiled one (as Java), you
have to compile first, the interactive_runner won't compile anything, it
only runs stuff.

Best,
Pablo

On Wed, May 1, 2019 at 2:29 PM vijender ahlawat 
wrote:

> Hi,
>
> I'm having issues with running interactive problem for JAVA.
>
> the interactive script says
> "python interactive_runner.py python testing_tool.py 0 -- ./my_binaRy"
>
> what is the mybinary, is it in python?
> How do we generate this script?
>
> There are no clear instructions on how to proceed or may be I'm not
> looking at the right place.
>
> Can someone please share the steps?
>
> --
> 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 post to this group, send email to google-code@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/google-code/b2d92912-9d6d-4b4e-b9fc-8adb4905b9aa%40googlegroups.com
> .
> For more options, visit https://groups.google.com/d/optout.
>

-- 
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 post to this group, send email to google-code@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/google-code/CANa5jcDamHPPy%3DFLbZfzFO3n%3DsRfZc9Zh0yBjVPNCKkQHC1YyQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: [gcj] Help with local testing on interactive problems - Windows 7, Python 3

2019-05-01 Thread 'Pablo Heiber' via Google Code Jam
Hi,

Return code 0 usually means "normal termination". From the testing tool it
means "no problem found". If you got the problem accepted it was likely
correct, so the output you are showing is to be expected. If you want to
experiment ahead of the next round, I suggest you modify your code to
introduce some kind of bug and re-run, to see how the output changes.

Best,
Pablo

On Wed, May 1, 2019 at 7:48 AM  wrote:

> On Friday, 26 April 2019 06:30:09 UTC-4, DahliaSR  wrote:
> > Hey Jeremy,
> >
> >
> > have a look into the source code of the interactive_runner and the
> testing_tool.
> > they tell you how to use them:
> >
> >
> > For Test Set 0 in the testing_tool:
> > py interactive_runner.py py testing_tool.py 0 -- py plzwork.py
> >
> >
> > For Test Set 1 in the testing_tool:
> >
> > py interactive_runner.py py testing_tool.py 1 -- py plzwork.py
> >
> >
> >
> > Am Do., 25. Apr. 2019 um 13:30 Uhr schrieb Jeremy Yip  >:
> > Hey guys, was just looking to get some help with how to run the local
> testing tool before round 2 - much appreciated!
> >
> >
> >
> > As below I am using the Golf Gophers testing tool from Code Jam 2019
> Round 1A:
> >
> > The testing tool is called testing_tool.py
> >
> > Interactive runner is interactive_runner.py
> >
> > My solution is plzwork.py
> >
> >
> >
> > All of these are in the same folder (\codejam)
> >
> > It seems that once I have navigated to the correct directory I can run
> each one individually:
> >
> > e.g. typing plzwork.py will run my script
> >
> > typing testing_tool.py 1 will run the second test set etc.
> >
> >
> >
> > If I try to run python3 plzwork.py or python interactive_runner.py it
> doesn't work.
> >
> >
> >
> > I've tried to run interactive_runner.py testing_tool.py 1 -- plzwork.py
> but get some [WinError 193] %1 is not a valid Win32 application.
> >
> >
> >
> > If anybody has any ideas would appreciate some help!
> >
> >
> >
> > --
> >
> > 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 post to this group, send email to googl...@googlegroups.com.
> >
> > To view this discussion on the web visit
> https://groups.google.com/d/msgid/google-code/feacd2ce-1418-42f0-b1ac-16605155df76%40googlegroups.com
> .
> >
> > For more options, visit https://groups.google.com/d/optout.
>
> Hi Jeremy and Dahlia,
>
> I am entirely new to the Google Code Jam, and I have issues with the
> interactive problems. So if my solution is in the file solution-PP.py, and
> I run the following command:
> python interactive_runner.py python testing_tool.py 1 -- python
> solution-PP.py,
> here is what is printed on the command line:
> Judge return code: 0
> Judge standard error:
> Solution return code: 0
> Solution standard error:
>
> Am I running the right sentence? I looked at interactive_runner.py and
> testing_tool.py, but I have problems understanding threads so I am not sure
> what should be printed. Is this print ok? I did run my solution on the
> website and it is accepted. I find deceiving because this doesn't seem to
> give any valuable information if I want to debug. In particular, it shows
> none of the results that are calculated.
>
> Thank you both very much for posting these messages.
>
> --
> 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 post to this group, send email to google-code@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/google-code/b897e2b3-50c7-4c44-b9f9-8f93dc0d43c8%40googlegroups.com
> .
> For more options, visit https://groups.google.com/d/optout.
>

-- 
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 post to this group, send email to google-code@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/google-code/CANa5jcA6gKOv_M9-4aXBXW%2BJuNAHdSq2iWLw7am7Zyd6JYvmvA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: [gcj] Help with local testing on interactive problems - Windows 7, Python 3

2019-05-01 Thread lfprevilleratelle
On Friday, 26 April 2019 06:30:09 UTC-4, DahliaSR  wrote:
> Hey Jeremy,
> 
> 
> have a look into the source code of the interactive_runner and the 
> testing_tool.
> they tell you how to use them:
> 
> 
> For Test Set 0 in the testing_tool:
>     py interactive_runner.py py testing_tool.py 0 -- py plzwork.py
> 
> 
> For Test Set 1 in the testing_tool:  
> 
>     py interactive_runner.py py testing_tool.py 1 -- py plzwork.py
> 
> 
> 
> Am Do., 25. Apr. 2019 um 13:30 Uhr schrieb Jeremy Yip :
> Hey guys, was just looking to get some help with how to run the local testing 
> tool before round 2 - much appreciated!
> 
> 
> 
> As below I am using the Golf Gophers testing tool from Code Jam 2019 Round 1A:
> 
> The testing tool is called testing_tool.py
> 
> Interactive runner is interactive_runner.py
> 
> My solution is plzwork.py
> 
> 
> 
> All of these are in the same folder (\codejam)
> 
> It seems that once I have navigated to the correct directory I can run each 
> one individually:
> 
> e.g. typing plzwork.py will run my script
> 
> typing testing_tool.py 1 will run the second test set etc. 
> 
> 
> 
> If I try to run python3 plzwork.py or python interactive_runner.py it doesn't 
> work. 
> 
> 
> 
> I've tried to run interactive_runner.py testing_tool.py 1 -- plzwork.py but 
> get some [WinError 193] %1 is not a valid Win32 application. 
> 
> 
> 
> If anybody has any ideas would appreciate some help!
> 
> 
> 
> -- 
> 
> 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 post to this group, send email to googl...@googlegroups.com.
> 
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/google-code/feacd2ce-1418-42f0-b1ac-16605155df76%40googlegroups.com.
> 
> For more options, visit https://groups.google.com/d/optout.

Hi Jeremy and Dahlia,

I am entirely new to the Google Code Jam, and I have issues with the 
interactive problems. So if my solution is in the file solution-PP.py, and I 
run the following command:
python interactive_runner.py python testing_tool.py 1 -- python solution-PP.py,
here is what is printed on the command line:
Judge return code: 0
Judge standard error: 
Solution return code: 0
Solution standard error: 

Am I running the right sentence? I looked at interactive_runner.py and 
testing_tool.py, but I have problems understanding threads so I am not sure 
what should be printed. Is this print ok? I did run my solution on the website 
and it is accepted. I find deceiving because this doesn't seem to give any 
valuable information if I want to debug. In particular, it shows none of the 
results that are calculated. 

Thank you both very much for posting these messages.

-- 
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 post to this group, send email to google-code@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/google-code/b897e2b3-50c7-4c44-b9f9-8f93dc0d43c8%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [gcj] Python/pypy viability for future Codejam rounds

2019-05-01 Thread Luke Pebody
No

On Wed, 1 May 2019, 1:46 pm Alex Wice,  wrote:

> @Luke Are you a codejam staff member?
>
> On Tuesday, April 30, 2019 at 11:09:42 PM UTC+9, Luke Pebody wrote:
> > Also, no the problems are not specifically tested to be solvable in
> Python
> >
> >
> > On Tue, 30 Apr 2019, 3:08 pm Luke Pebody,  wrote:
> >
> > I did Problem C large in Python
> >
> >
> > On Tue, 30 Apr 2019, 3:05 pm Alex Wice,  wrote:
> > In 2019 round 1B, problem C large doesn't seem to be possible with Pypy.
> >
> > If this is true, are the problems not specifically tested to be possible
> with Python?
> >
> >
> >
> > --
> >
> > 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 post to this group, send email to googl...@googlegroups.com.
> >
> > To view this discussion on the web visit
> https://groups.google.com/d/msgid/google-code/720185a5-eddf-4977-8058-377f23c5574f%40googlegroups.com
> .
> >
> > For more options, visit https://groups.google.com/d/optout.
>
> --
> 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 post to this group, send email to google-code@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/google-code/c92a77c2-a2de-48b4-ab53-a8f1c5969c57%40googlegroups.com
> .
> For more options, visit https://groups.google.com/d/optout.
>

-- 
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 post to this group, send email to google-code@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/google-code/CAECKw-OL0b5Zk%2B2WS35uz2g%3D-PGfk6BunOum-9pBj2c0efkJdw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: [gcj] Is the scoring rule strange?

2019-05-01 Thread Luke Pebody
Yes, this is correct.

On Wed, 1 May 2019, 1:46 pm 姚炫容,  wrote:

> Bartholomew Furrow於 2019年4月30日星期二 UTC+8下午11時09分58秒寫道:
> > During the contest, you can't see whether you solved hidden inputs
> correctly or not. The score you see on the scoreboard, which I'll call your
> "apparent score," is what your score would be if you solved every possible
> hidden input correctly. If you make an additional attempt, your apparent
> score can only get worse -- but your real score might get better.
> > For example, if you first submit O(N^2) code for a problem with a hidden
> input of size 10^6, then later submit O(N) code, your apparent score goes
> down (because your submission is now later), but your actual score could go
> up.
> >
> >
> > Does that help?
> > Bartholomew
> >
> >
> > On Tue, Apr 30, 2019 at 8:05 AM 姚炫容  wrote:
> > Once your attempt solve all the test set(visible and hidden), then any
> additional attempt will lower your final score for penalty time, or even
> for the score.
> >
> >
> >
> > Is it right?
> >
> >
> >
> > --
> >
> > 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 post to this group, send email to googl...@googlegroups.com.
> >
> > To view this discussion on the web visit
> https://groups.google.com/d/msgid/google-code/033b23a0-066c-43b2-8499-ac06b80872df%40googlegroups.com
> .
> >
> > For more options, visit https://groups.google.com/d/optout.
>
> yes, but if my first submit is O(N) and solve all the test set, then any
> additional submit will make my score worse.
>
> --
> 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 post to this group, send email to google-code@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/google-code/957cd774-75b9-4c65-bc17-4856b522b17e%40googlegroups.com
> .
> For more options, visit https://groups.google.com/d/optout.
>

-- 
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 post to this group, send email to google-code@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/google-code/CAECKw-MshbPGHjUyBQO75u7oiHXK%3DVv00yXts8o-aB4vmS0JLg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: [gcj] Is the scoring rule strange?

2019-05-01 Thread 姚炫容
Bartholomew Furrow於 2019年4月30日星期二 UTC+8下午11時09分58秒寫道:
> During the contest, you can't see whether you solved hidden inputs correctly 
> or not. The score you see on the scoreboard, which I'll call your "apparent 
> score," is what your score would be if you solved every possible hidden input 
> correctly. If you make an additional attempt, your apparent score can only 
> get worse -- but your real score might get better.
> For example, if you first submit O(N^2) code for a problem with a hidden 
> input of size 10^6, then later submit O(N) code, your apparent score goes 
> down (because your submission is now later), but your actual score could go 
> up.
> 
> 
> Does that help?
> Bartholomew
> 
> 
> On Tue, Apr 30, 2019 at 8:05 AM 姚炫容  wrote:
> Once your attempt solve all the test set(visible and hidden), then any 
> additional attempt will lower your final score for penalty time, or even for 
> the score.
> 
> 
> 
> Is it right?
> 
> 
> 
> -- 
> 
> 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 post to this group, send email to googl...@googlegroups.com.
> 
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/google-code/033b23a0-066c-43b2-8499-ac06b80872df%40googlegroups.com.
> 
> For more options, visit https://groups.google.com/d/optout.

yes, but if my first submit is O(N) and solve all the test set, then any 
additional submit will make my score worse.

-- 
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 post to this group, send email to google-code@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/google-code/957cd774-75b9-4c65-bc17-4856b522b17e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [gcj] Question about Code Jam 2019 Round 1B second problem - Draupnir

2019-05-01 Thread Ramesh Kumar
On Tuesday, April 30, 2019 at 11:19:29 PM UTC+5:30, DahliaSR wrote:
> Hello,
> 
> 
> >> "But, for example after 68 days, it will contribute R1*2^5 rings to the 
> >> total rings, right?"
> 
> 
> That's wrong! It still does contribute 0.
> The number of R1 contributes 0 total for ANY day larger then 62.
> Why is that? :
> Day 63:    R1 * 2^63 ≡ 0 (mod 2^63)        2^63 is a multiple of 2^63 so the 
> remainder MUST be 0
> Day 64:    R1 * 2^64 ≡ 0 (mod 2^63)        2^63 is a multiple of 2^63 so the 
> remainder MUST be 0
>                 R1 * 2^(63 + 1) ≡ 0 (mod 2^63)        2^64 is less than 2^63 
> and therefore a multiple 2^63 so the remainder STILL MUST be 0.
> 
> 
> So when querying day 324, you can ONLY identify R(6) at day 0.
> 
> 
> Am Di., 30. Apr. 2019 um 17:35 Uhr schrieb Ramesh Kumar :
> On Tuesday, April 30, 2019 at 8:18:56 PM UTC+5:30, /dev/joe wrote:
> 
> > The 1-day rings duplicate every day, so their contribution to the sum moves 
> > one bit left in the binary representation every day. After 63 days, since 
> > we only get the value mod 2^63, the 1-day rings make no contribution to the 
> > value you get.
> 
> > 
> 
> > 
> 
> > On Tue, Apr 30, 2019 at 10:05 AM Ramesh Kumar  wrote:
> 
> > Hi All,
> 
> > 
> 
> > 
> 
> > 
> 
> > It was mentioned we can use two chances for Code Jam 2019 Round 1B second 
> > problem -  Draupnir. But I think we can use only one number 324 which is 
> > sufficient and find the solution. But, I am unable to get the accepted 
> > answer. Is there anything wrong to use only 324 number to find all the 
> > required six numbers? Please help me to understand.
> 
> > 
> 
> > 
> 
> > 
> 
> > -- 
> 
> > 
> 
> > 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 post to this group, send email to googl...@googlegroups.com.
> 
> > 
> 
> > To view this discussion on the web visit 
> > https://groups.google.com/d/msgid/google-code/10442015-c57d-4edd-9ac4-dce29cd20eb2%40googlegroups.com.
> 
> > 
> 
> > For more options, visit https://groups.google.com/d/optout.
> 
> 
> 
> But, for example after 68 days, it will contribute R1*2^5 rings to the total 
> rings, right?
> 
> 
> 
> -- 
> 
> 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 post to this group, send email to googl...@googlegroups.com.
> 
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/google-code/c27fe3f0-935e-4ce9-bdcf-b3f31fb422f9%40googlegroups.com.
> 
> For more options, visit https://groups.google.com/d/optout.

Thank you all for the explanation. Now I understood what was my mistake which 
cost me the qualification to Round 2. I had little confusion in calculating 
modulo. Now I am clear. One last chance I have in Round 1C. I have to wait and 
see if I can clear the round. 

-- 
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 post to this group, send email to google-code@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/google-code/bac7360a-619e-40e5-81fc-f5e1cd29d9aa%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [gcj] Python/pypy viability for future Codejam rounds

2019-05-01 Thread Alex Wice
@Luke Are you a codejam staff member?  

On Tuesday, April 30, 2019 at 11:09:42 PM UTC+9, Luke Pebody wrote:
> Also, no the problems are not specifically tested to be solvable in Python
> 
> 
> On Tue, 30 Apr 2019, 3:08 pm Luke Pebody,  wrote:
> 
> I did Problem C large in Python
> 
> 
> On Tue, 30 Apr 2019, 3:05 pm Alex Wice,  wrote:
> In 2019 round 1B, problem C large doesn't seem to be possible with Pypy.
> 
> If this is true, are the problems not specifically tested to be possible with 
> Python?
> 
> 
> 
> -- 
> 
> 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 post to this group, send email to googl...@googlegroups.com.
> 
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/google-code/720185a5-eddf-4977-8058-377f23c5574f%40googlegroups.com.
> 
> For more options, visit https://groups.google.com/d/optout.

-- 
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 post to this group, send email to google-code@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/google-code/c92a77c2-a2de-48b4-ab53-a8f1c5969c57%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[gcj] Code Jam 2018 - Round 2 Q3 - Costume Change - difficulties with python and time limit

2019-05-01 Thread Jeremy Yip
Hi guys,

I've been trying question 3 from round 2 last year and am not sure whether I am 
getting a TLE error because I am not fast enough or because of the programming 
language. I believe the following is O(N^3) - if anybody has any ideas that 
would be a big help!:

class Graph:
def __init__(self, graph):
self.graph = graph
self.nodes = len(graph) #- number of nodes

def dfs_path(self, start, end): #- returns the path from start to end, 
otherwise returns False
queue = [(start, [start])]
while queue:
(vertex, path) = queue.pop()
for neighbour in self.graph[vertex] - set(path):
if neighbour == end:
return path + [neighbour]
else:
queue.append((neighbour, path + [neighbour]))
return False

def reverse_edge(self, v1, v2): #- reverses the edge v1 -> v2 to v2 -> v1
self.graph[v1].remove(v2)
self.graph[v2].add(v1)


def mcbm(self):
n =(self.nodes // 2)
count = 0

self.graph["source"] = set(range(n)) #-- row nodes are (0, 1, ..., n-1)
self.graph["sink"] = set()

for node in range(n, 2*n):
self.graph[node].add("sink") #-- column nodes are (n, n+1, ..., 
2*n-1)

while self.dfs_path("source", "sink"): #-- while there exists a path
path = self.dfs_path("source", "sink")
length = len(path)

L = path[1] #-- L exposed node
R = path[length-2] #-- R exposed node

count += 1
self.graph["source"].remove(L) #--- disconnect L, R from source, 
sink
self.graph[R].remove("sink")

for i in range(1, length-2): #--- reverse all the edges in path 
between L and R
self.reverse_edge(path[i], path[i+1])

return count

def coords_to_graph(coords, n): #--- converts set of coordinates on a n by n 
grid to a graph
nodes = [int(x) for x in range(2*n)] #--- nodes are (0, n) for rows and (n, 
2n) for cols
graph = {}
for node in nodes:
graph[node] = set()

for coord in coords: #--- connect the node for row x to the node for column 
y (i.e. node y+n)
x, y = coord[0], coord[1]
graph[x].add(y+n) 

return graph

def solve():
n = int(input())
colour_dict = {}

for colour in range(1, 2*n+1): #--- the colours are 1, 2, ..., n and -1, 
-2, ..., n 
colour_dict[colour] = set() #--- this corresponds to 1, 2, ..., 2n (mod 
2n+1)

for row in range(n):
cur_row = [int(x) for x in input().split()]
for index, value in enumerate(cur_row):
colour = value % (2*n+1) #--- basically convert the -ve numbers to 
n+1, n+2, ..., 2n
colour_dict[colour].add((row, index))

for colour in colour_dict:
cur_graph = Graph(coords_to_graph(colour_dict[colour], n))  
result = (len(colour_dict[colour]) - cur_graph.mcbm())

yield result



#--
t = int(input())
for case in range(t):
print ("Case #" + str(case + 1) + ": " + str(sum(solve(

-- 
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 post to this group, send email to google-code@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/google-code/844e156a-7e37-4a6a-b37b-41858fc73187%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [gcj] Python/pypy viability for future Codejam rounds

2019-05-01 Thread Luke Pebody
This was my source code:
from sys import stdin, stdout, stderr

def get_int():
return int(stdin.readline())

def get_ints():
return tuple(int(z) for z in stdin.readline().split())

# Quickly calculate cumulative sums of a sequence
# And quickly increment or decrement individual elements of it
class seq:
def __init__(self, n):
self.n = n
self.a = [0] * (n + 1)

def inc(self, i, j):
while i <= self.n:
self.a[i] += j
i += (i & -i)

def cumul(self, i):
tot = 0
while i > 0:
tot += self.a[i]
i -= (i & -i)
return tot

class SpecialSet:
def __init__(self, n):
self.n = n
self.abv = seq(n+2)
self.abv.inc(1, n+2)
self.blw = seq(n+2)
self.blw.inc(1, 1)

def remove(self,k):
b = self.blw.cumul(k)
dif = self.abv.cumul(b) - k
self.abv.inc(b, dif)
self.abv.inc(k, -dif)

a = self.abv.cumul(k)
dif = self.blw.cumul(a) - k
self.blw.inc(a + 1, -dif)
self.blw.inc(k + 1, dif)

def add(self, k):
b = self.blw.cumul(k)
dif = self.abv.cumul(b) - k
self.abv.inc(b, -dif)
self.abv.inc(k, dif)

a = self.abv.cumul(k)
dif = self.blw.cumul(a) - k
self.blw.inc(a + 1, dif)
self.blw.inc(k + 1, -dif)

def above(self, k):
return self.abv.cumul(k)

def below(self, k):
return self.blw.cumul(k)

def scr(i, lE, hE, tL, tH):
return max(tH-i,0)*max(min(i,lE)-tL,0) +
max(tH-max(hE,i),0)*max(i-max(lE,tL),0)

other = {'C':'D','D':'C'}

for cn in xrange(1,1+get_int()):
(N,K) = get_ints()
cs = get_ints()
ds = get_ints()
swords = [(cs[i],i+2,'C') for i in xrange(N)]+[(ds[i],i+2,'D') for i in
xrange(N)]
swords.sort()

stillValid = {}
stillValid['C'] = SpecialSet(N)
stillValid['D'] = SpecialSet(N)

tooGood = {}
tooGood['C'] = SpecialSet(N)
tooGood['D'] = SpecialSet(N)

w = 2 * N - 1
w2 = 2 * N - 1

tot = 0
while w >= 0:
(str, indx, p) = swords[w]
# sword is valid
stillValid[p].add(indx)
# remove swords that aare stronger than K + str
while swords[w2][0] > K + str:
tooGood[swords[w2][2]].add(swords[w2][1])
w2 -= 1
# count the number of ranges that:

# (i) do not include any too good sword
tooHigh = min(tooGood[q].above(indx-1) for q in 'CD')
tooLow = max(tooGood[q].below(indx+1) for q in 'CD')

# (ii) do not include any other still valid sword for p
tooHigh = min(tooHigh, stillValid[p].above(indx))
tooLow = max(tooLow, stillValid[p].below(indx))

# (iii) do include a still valid sword for otherp
otherp = other[p]
highEnough = stillValid[otherp].above(indx-1)
lowEnough = stillValid[otherp].below(indx+1)

sc = scr(indx, lowEnough, highEnough, tooLow, tooHigh)
tot += sc
w -= 1

print "Case #{}: {}".format(cn, tot)
if (cn == -1):
break

On Tue, Apr 30, 2019 at 3:09 PM Luke Pebody  wrote:

> Also, no the problems are not specifically tested to be solvable in Python
>
> On Tue, 30 Apr 2019, 3:08 pm Luke Pebody,  wrote:
>
>> I did Problem C large in Python
>>
>> On Tue, 30 Apr 2019, 3:05 pm Alex Wice,  wrote:
>>
>>> In 2019 round 1B, problem C large doesn't seem to be possible with Pypy.
>>> If this is true, are the problems not specifically tested to be possible
>>> with Python?
>>>
>>> --
>>> 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 post to this group, send email to google-code@googlegroups.com.
>>> To view this discussion on the web visit
>>> https://groups.google.com/d/msgid/google-code/720185a5-eddf-4977-8058-377f23c5574f%40googlegroups.com
>>> .
>>> For more options, visit https://groups.google.com/d/optout.
>>>
>>

-- 
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 post to this group, send email to google-code@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/google-code/CAECKw-O-x-HhfcsfKx9swsF-ixm3HC3ZKWN65DFTN4iThoBqAA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.