i am getting a run-time error(NZEC) for most of my submissions. I usually code in python 2.7 and 3.5 and this is annoying me a lot can someone tell why this is happening and what should i do to avoid this…
please help i am unable to solve most of the problems because of this.
everything works perfectly fine in other ide’s but during submission it just shows this error???
Have you checked the input method? Sometimes trailing spaces/whitespaces/extra lines are unintentionally present in TC. A strong method is able to overcome all these obstacles while weaker one gives NZEC. Sorry, cant recall exact function atm.
Maybe the problem is in input().split(" ") instead try input().split(), using first one fails if there are extra spaces between two numbers(for example “1 2”.split() will return [‘1’,’’,‘2’] while second one returns [‘1’,‘2’])
I went through some of your submissions. I feel that you are using unnecessary loops for taking arrays as inputs. Here is a simple one-liner to input an array of integers: arr = map(int, raw_input().strip().split())
In case of array of strings, just arr = raw_input().strip().split() would suffice.
The above code is in Python 2, in case you want to use Python 3, replace raw_input() by input().
But since maps and lists are not the same in Python 3, unlike Python 2, you must convert the map to list, by using list(arr). Another alternative is using list comprehension, to avoid map. The one liner for list comprehension in Python 3 would be arr = [int(i) for i in input().strip().split()]
Now, most NZECs for Python on online judges are due to extra whitespaces. To avoid whitespaces, you can use strip almost each time you take an input. I have been doing so without any issues. Now, coming to split() and split(’ ‘), these two aren’t the same. When you use split() i.e without a delimiter, Python considers any amount of consecutive whitespaces as a delimiter, but in case of split(’ ') i.e with a single space as delimiter it considers only single whitespace as a delimiter. You can read more about it here, or refer the python docs.
thanks a lot let me try your suggestions this thing annoyed me a lot and also i am new to codechef and my reputation is <3 i was unable to ask questions.