noob_Coder
noob_Coder

Reputation: 19

Always getting Run Time Error in Google Code jam

I wrote my code in python-3 in google Code jam unfortunately,I am always getting Run time Error , though the code it correct and is getting executed in jupyter notebook.

I already found one answer to this question but I am not clear with the solution on how to implement it, so can someone please give me solution for this problem .

Here is my code-

import numpy as np
n = int(input())
a = []
b = []
t = []
for i in range(n):
    a.append(int(input()))
    for j in range(a[-1]):
        t.append(list(map(int, input().split())))

        b += t
        t = []
    x = a[0]
    k = 0


def cal(temp):
    row = 0
    k = 1
    for i in temp:
        dict = {}
        flag = 0
        for j in i:
            if j not in dict.keys():
                dict[j] = 1
                flag = 0

            else:
                flag = 1
                break

        if flag == 1:
            row += k
    return row


def func(temp):
    temp = np.array(temp)
    t = 0
    row = cal(temp)
    for i in range(len(temp)):
        t += temp[i][i]

    col = cal(temp.T)
    return t, row, col


for i in range(n):
    q = func(b[k:x])

    d = i + 1
    print("Case #{}: {} {} {}".format(d, q[0],q[1],q[2]))

    k = x
    x += a[i]

Upvotes: 0

Views: 2492

Answers (2)

ThunderHorn
ThunderHorn

Reputation: 2035

Helper function for the inputs I wont give you any logic but this will help you work with the google Judge system

def solve(matrix, size):
   return "{} {} {}".format(a, b, c)

for T in range(1, int(input()) + 1):
    size = int(input())
    matrix = [input().split(' ') for i in range(size)]
    print("Case #{}: {}".format(T, solve(matrix, size)))

Upvotes: 0

Gareth Ma
Gareth Ma

Reputation: 707

numpy and other external libraries are not available. Also f strings do not work as mentioned.

Also throughout your whole code, you did not use any numpy functions anyways, so just replace it with a normal python list and it should work fine.

Good luck in GCJ~

Upvotes: 1

Related Questions