I use Python3 as my primary language while programming and recently started using CodeForces ( I used only CodeChef untill now and never faced a problem !) and today, in the 3rd contest that I was participating in on CodeForces I faced severe problems because of using Python3 !!!
Faced the following problem in the Problem B of Contest #1027(Educational Codeforces Round 49 )
I coded a perfectly correct Solution in Python3 but got a TLE in 3rd test case !
Then I coded the same solution in C++, but I'm not that good with C++ so I actually got a WA in test 7 which I figured was due to my data type, I tried around with that, read online and was finally able to get it working by changing the data type and some minor adjustments to my initial code ! All this took me 1 hour ! Now wasting 1 hour in a live contest just because CodeForces doesn't have a different Time Limit for different languages is insane !!!!!!!!
I found a blog(https://mirror.codeforces.com/blog/entry/45228) pointing out the same issue which was posted 2 years back ! But it seems that still nothing has been done !
I'm attaching as a proof a screenshot showing my submissions, anyone can go ahead and see my codes and realise that I wasted my 1 hour because I wasn't as well versed with C++ as with Python ! And a having different a Time Limit for Python would have saved my time because the logic and the solution remains exactly the same !!!!!!!
Edit : I am seeing that this blog is also starting to follow the downvote trend as the one I have linked ! Guys stop downvoting ! I get the point being made by the downvoters ! I understand that Python is slow and this is a competitive space !
I agree that there should not be a multiplier but there could be then a defined time limit for each question in each language using the same solution ! I agree multipliers don't work well and always keeps someone at an advantage or a disadvantage ! But there are a lot of languages that CodeForces supports, so either is stops supporting them in contests or has a defined time limit for each question serperately for each problem because the current scenario won't allow any other language to progress in the competitive world ! And just to counter the logic being given by some people that the fastest should be used, then why aren't we all using Assembly ? ! Same is what I want to say for the case of Python !
And also, I have found a solution for the problem I faced today(pointed out by @vovuh) : Using sys.stdin.readline() instead of input() does help a bit and may solve the problem sometimes !
Edit 2: Nice point made by @manetsus. I think I'll now look a bit deeper into both the languages to understand them and be able to decide which one to use beforehand !
Glad I posted my problem, learning a lot from the guys out here ! Anyone reading this, do leave out your tips in the comments !
Edit 3: I'm astonished at the amount of downvotes I'm getting ! The community here at CodeForces doesn't seem to be welcoming of Python ! I think I should have removed this blog after I got some help because now I don't see anymore helpful comment and all I'm getting is downvotes :/ !
This issue has been discussed before multiple times. The general consensus is that competitive programming is competitive so if you're going to choose a slower language (like Java or especially Python) you need to be ready to deal with the potential setbacks and advantages of your chosen language. Codeforces isn't supposed to accommodate your language choice especially if it's a poor one that is known to be slower than something like C++.
So if you don't want to deal with these issues, you can switch languages to something that will run faster. Obviously it's fine to voice frustrations but you shouldn't expect Codeforces to change its entire contest format to accommodate poor decisions.
Okay guys stop downvoting me ! I got the point ! Read the updated post !
I definitely did not mean to imply that. There are different advantages and disadvantages to different languages so if Codeforces can provide compilers for those languages, then they should. Python's easy to type in and has a lot of convenient built in structures and methods so if the bounds are small enough, it might be faster to type something out in Python. Java has some convenient classes like BigIntegers and BigDecimals that make it easier to deal with certain problems. And of course, c++ is the fastest language to use (and probably has other advantages that I don't really know).
To say that Codeforces should disable slower languages is a big step from requesting Codeforces to change because you picked a language that was too slow.
In this problem you can use sys.stdin/sys.stdout to fast up your input/output. It is well-known fact that IO in Python is very slow (even slower than Python), you can and (in some problems) must speed it up. Replace input() with sys.stdin.readline() and you will get AC (excepting the fact your last python solution gets WA8).
Hey Thanks for tip ! It does seem to work better !
But its exactly the same logic as my AC C++ code so I don't know what is causing a WA8 !
Hey! It is not just a logic contest. You have to implement the logic in a better way. You know, for C++,
size()
function in string costsO(1)
andstrlen()
function inchar
array costsO(n)
. If you implement somewherestrlen()
wheresize()
could serve the purpose and say, "Oh! you are giving TLE, but the logic is same!", would it be a good logic?Come on man! You can express your frustration, but can not blame! There are a lot of python guys. They would help you, gather techniques of python from them. You would be appreciated, but eliminating Python from CF is not that logical.
Thanks.
@manetsus
Hmm, that's true ! Good point ! I agree with your view. I think I'll now look a bit deeper into both the languages to understand them and be able to decide which one to use beforehand ! Thanks for your view :) !
Just to verify that I didn't make any change in my C++ code I rewrote my C++ code in Python (https://mirror.codeforces.com/contest/1027/submission/41799053) And got an AC !!!!!!!
Thanks for this awesome IO fact @vovuh ! This will help !
You're welcome :) I'm also can advice you to submit all your Python code using PyPy instead of Python because in most cases PyPy is much faster than Python (but in this problem it's not helping). Hope I help you :)
P.S. But, as I remember, for some problems Python works faster than PyPy (but in general this is not true). Choice is yours :)
Auto comment: topic has been updated by HarendraSingh22 (previous revision, new revision, compare).
Auto comment: topic has been updated by HarendraSingh22 (previous revision, new revision, compare).
Auto comment: topic has been updated by HarendraSingh22 (previous revision, new revision, compare).
Just my opinion about this blog. I think the CF community should stop downvoting HarendraSingh22 because this is not his fault. There is unspoken rule for every CF round: the first two or three problems of every round should be acceptable without any great optimizes of IO or the other such things. So if the contestant has right complexity (even if he writes his solution on slow programming language without any optimizes) he should get AC. This issue (in this round) is my fault because usually I write the python solution without any optimizes for the problems A-C, but this time I didn't do that. I am really sorry for that and if the CF community wants to downvote something, please, downvote my blogs/comments because it's only my fault.
Thanks vovuh sir for your kind words ! But it seems like the community here is quite extremist ! Though I agree that multipliers for slow languages are bad because they sometimes give unfair advantages too. But I do feel that there should be different Time Limits for each question in different languages just to support multiple languages !
If you didn't face the problem on codechef it's because they use a multiplier (5x for python) https://blog.codechef.com/2009/04/01/announcing-time-limits-based-on-programming-language/