Блог пользователя darkshadows

Автор darkshadows, история, 8 лет назад, По-английски

Throughout the year, Code Jam hosts online Kickstart rounds to give students the opportunity to develop their coding skills, get acquainted with Code Jam’s competition arena, and get a glimpse into the programming skills needed for a technical career at Google.

Inviting you to solve some fun and interesting problems with Professor Shekhu and Akki this Sunday(hopefully in your timezone as well!) Oct 22 05:00 UTC – 08:00 UTC.

You'll find the link to contest dashboard at https://code.google.com/codejam/kickstart/ on the day of the contest. Also, we'll try to publish analysis as early as possible.

  • Проголосовать: нравится
  • +33
  • Проголосовать: не нравится

»
8 лет назад, скрыть # |
 
Проголосовать: нравится +72 Проголосовать: не нравится

Will the scoreboard of previous round ever be fixed?

»
8 лет назад, скрыть # |
 
Проголосовать: нравится +25 Проголосовать: не нравится

Does anyone from any APAC of this year get interview call?

just curious to know.

»
8 лет назад, скрыть # |
 
Проголосовать: нравится +20 Проголосовать: не нравится

The scoreboard is still broken.

»
8 лет назад, скрыть # |
 
Проголосовать: нравится +15 Проголосовать: не нравится

Please at least mention the number of people who solved each problem in the analysis after the contest ends.

»
8 лет назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

DP everywhere.

»
8 лет назад, скрыть # |
Rev. 2  
Проголосовать: нравится -10 Проголосовать: не нравится

Can anyone tell me why the following code for Problem A is wrong?

The idea is to first find the repeated length r of A^n mod P,

then find the value of N! mod r.

Then the result will be A^r mod P.

Code
  • »
    »
    8 лет назад, скрыть # ^ |
    Rev. 3  
    Проголосовать: нравится 0 Проголосовать: не нравится

    the problem is suppose repeated length is "C". and it repeats after first "X" terms and Q=n!. then answer is (Q-X)%C=((Q%C-X%C)%C). In your notion (r=C) . You forgot to take into account X. example a=2 mod=12 then a^0=1,a^1=2,a^2=4,a^3=8,a^4=4,hence X=2,C=2.

    • »
      »
      »
      8 лет назад, скрыть # ^ |
       
      Проголосовать: нравится 0 Проголосовать: не нравится

      Thank you for your reply!

      I also considered this condition at the first time. But then I realize that:

      If A^m mod P == A^n mod P, then A^{m-1} mod P == A^{n-1} mod P. So that X must be 0.

      What is the flaw in the above mentioned statement? Thanks again.

    • »
      »
      »
      8 лет назад, скрыть # ^ |
       
      Проголосовать: нравится 0 Проголосовать: не нравится

      Sorry I did not notice your example just. Let me think for a moment...

      • »
        »
        »
        »
        8 лет назад, скрыть # ^ |
         
        Проголосовать: нравится 0 Проголосовать: не нравится

        I have submitted using similar idea you can see my code link. Though there exist a very simple answer of that question. see this code. this rajat's code

        • »
          »
          »
          »
          »
          8 лет назад, скрыть # ^ |
          Rev. 2  
          Проголосовать: нравится 0 Проголосовать: не нравится

          Thanks for your kindly reply! Finally I also got my code accepted:

          Code
»
8 лет назад, скрыть # |
 
Проголосовать: нравится +4 Проголосовать: не нравится

How to solve problem A , Is that so easy :(
I didn't get how to approach that problem.

»
8 лет назад, скрыть # |
 
Проголосовать: нравится +3 Проголосовать: не нравится

Here is my editorial.

Problem 1. A^(N!) = (...(((A^1)^2)^3)...)^N

def solve(A, N, P):
    for e in xrange(1, 1 + N):
        A = pow(A, e, P)
    return A

Problem 2. Draw an edge (i, j) if on some card i is paired with some card j. There are N-1 unique edges. We want the lowest sum of edges such that we form one connected component with the edges — this is just an MST.

class DSU:
    #details omitted
    
def solve(N, A, B):
    cards = zip(A, B)
    edges = [(min(c[0] ^ d[1], c[1] ^ d[0]), i, j)
             for i, c in enumerate(cards)
             for j, d in enumerate(cards) if i < j]
    edges.sort()
    dsu = DSU(N)
    return sum(dsu.union(i, j) and cost
               for cost, i, j in edges)

Problem 3. Let dp(r1, c1, r2, c2) be the answer for the submatrix with those corners. For each of the (r2-r1) + (c2-c1) cuts, calculate the answer recursively. It depends on being able to query the minimum value that occurs in r1, c1, r2, c2.

def solve(A, R, C):
    def lookup_min(r1, c1, r2, c2):
        #details omitted
    
    @memoize
    def dp(r1, c1, r2, c2):
        if r1 == r2 and c1 == c2: return 0
        ans = None
        for r in xrange(r1, r2):
            ans = max(ans, dp(r1, c1, r, c2) + dp(r+1, c1, r2, c2))
        for c in xrange(c1, c2):
            ans = max(ans, dp(r1, c1, r2, c) + dp(r1, c+1, r2, c2))
        return ans + lookup_min(r1, c1, r2, c2)
    
    return dp(0, 0, R-1, C-1)
»
8 лет назад, скрыть # |
 
Проголосовать: нравится -8 Проголосовать: не нравится

Solutions & Explanations have been updated here: http://ckcz123.com/blog/posts/kickstart-2017-round-g/