### beethoven97's blog

By beethoven97, history, 7 weeks ago,

I know that this problem supposed to be a trivial problem , but I stay in it about 1 hour and i don't know why it get WA on test 3 about 10 times of submissions and i submitted the solution with python and c++ as i thought that WA is due to precision error but both of them didn't get accepted.

c++ code
python code

• +3

By beethoven97, history, 3 months ago,

I write this blog to talk about arrays in python . As we know python lists is slow and a memory consumption because it can't assign uniform data type unlike other low languages like c and c++ ,you can read more about that in this documentation.

but there is an efficient way to make arrays like c++ ,it's the array module ,I will discuss about it and its powerful differences in terms of time and memory between it and lists.

1. what is python array ?

python array is an array module implemented in c language unlike lists which is a cpython implementation ,it must determine a datatype like c arrays.

you can import it by the following line :

from array import array


it contains most of c datatypes like 32 bit integer :'i' ,64 bit integer :'q' , double values :'d', chars:'u'. but it doesn't contains string datatype.

1. How to use it?

it's very similar to python lists in usage and contains most of lists functions like insert , append , count,... but the difference is that you must define array data type first . you can see this for more understanding.

But array doesn't contain sort function but you can do the following for sorting:

from array import array
#'i' means integer 32 bit datatype
a=array('i',sorted([2,3,4,1]))

1. examples

Here some codes to show the time and memory consumptions: — dp problem: array vs list

-graph problem 717ms using list vs 514ms using array module

Notice that not only array is faster than list but it's also less than list in terms of memory space, as you can see in the previous dp problem lists uses 77500 KB but array uses 30800 KB which is less than half of lists memory usage.

finally ,I think that array module is really useful in python competitive programming unlike lists.

• +15

By beethoven97, history, 6 months ago,

i solved the following problem it get accepted in pypy3 32 bit code ,but it get TLE in pypy3 64 bit code,i used re library for regular expression .can any one explain this weird behavior between pypy 32 bit and pypy 64 bit with solving re problems ?

Upd: I tried to submit this code in new version of pypy-64bit but it still gives TLE and it's accepted in pypy3 32bit ,is there any bug in re library in pypy64 bit ?

• 0

By beethoven97, history, 21 month(s) ago,

i try to solve this problem for two days but i always get wrong answer on test 7 here is my submission i use bfs with memomization and i take the smallest character after every step .

please can someone help me to get this submission accepted and any solution will be appricated.

• -19

By beethoven97, history, 22 months ago,

i try to submit this problem The Hard Work of Paparazzi my pypy2 solution get TLE in test9 but my pypy3 solution get accepted can any one explain this two solutions why pypy3 get accepted and not pypy2 although pypy2 faster than pypy3?

• 0

By beethoven97, history, 2 years ago,

i try to solve an iteractive problem but i get idleness limit exceeded several times can someone help me to solve this error please .

here is the problem and my code

• 0

By beethoven97, history, 2 years ago,

__in this problem D. Vasiliy's Multiset

i implement trie data structure in python language but i face memory limit exceeded in test 91 ,can someone please help me in optimize the memory of class trie and be accepted .

• 0

By beethoven97, history, 2 years ago,

Codeforces Round #428 div2 problem C. Journey link to problem.. i recieved wrong answer on test 30 (wrong output format Unexpected end of file — double expected). can any one understand this wrong answer ?? here is my python code :(https://codeforces.com/contest/839/submission/75015613)