same thing happened to me. c++ bigint code gets TLE
To all who thinks that this problem is just about parsing, implementation and programming languages(especially as @alexvaleanu)
Authorâs solution implemented in C++ and doesnât require any big numbers arithmetic. Editorial will be updated soon. Now you can have a look at authorâs solution.
Sorry for the situation with many solutions easily passed using Python or Java, that wasnât supposed(but itâs programming contest and I think itâs ok to use advantages of the languages though it wasnât planned).
Also I think you should at first think about possible alternative algorithm ideas(by the way not absolutely obvious) before writing: âWorst problem of all timeâ
The difficulty says âTo be updated soonâ. Isnât it decided during problem setting??
Although I missed the contest, I was trying to solve the problems! When I solved this problem in python, the following code worked perfectly for me:
T = int(raw_input())
for t in range(T):
M, S = map(str, raw_input().split())
`
M = int(M)
S = eval(S)
print S%M
However, when I checked a few solutions, they were way too long codes!!! Is my code wrong?
Your code will only work for the first subtask. IT will timeout for the rest.
can anyone explain the authorâs solution? I have no idea how, exponetiation happened in itâŚ
Nice problem, I guess itâs unfortunate that it could be solved so easily with other languages.
Why doesnât the editorial describe this solution instead of talking about the obvious brute force bignum algorithm? The reason everyone is raging here is because it looks like the official and expected solution is to use Python/Java because thatâs the only solution described in the editorial. If your solution had been posted as the editorial then I doubt as many people would have complained.
Please explain the exponentiation part of the authorâs solution. I believe this is a very useful problem for C,C++ programmers.
authorâs solution is giving wrong answer
consider this input:
1
10000 2x3x4x5
answer should be =120
authorâs answer = 1
String cannot be input this manner. Its of the format (a1)(a2)(a3)âŚan where each ai is of the form bi**bj.
Itâs still possible to write a solution quite a bit shorter than the ones most contestants have done.
It is updated now, but in general deciding a difficulty after the contests is better, because a number of contestants who solve it correctly affect the level of difficulty. For example, there can be an unexpected method of solving it which comes up during a contest.
@pavel1996 when i use author solution and replace in solve()
for (int i=0;i<l;i++)
with
for (int i=0; s[i] != â\0â; i++)
i got WA. can you tell me why?
while Calculating modulo of
A % M , M < 10^8
A = 10^(k-1) * dk-1 + 10^(k-2) * dk-2 + ... + d0
A % M = (10^(k-1) * dk-1) % M + (10^(k-2) * dk-2) % M
how are we handling for k > 30 ?
It was a good problem and can be coded easily in C++ if one remembers basic arithmetic operations and the logic behind them. I did it easily.
http://www.codechef.com/viewsolution/6589294
This is fetching only 70 points. Itâs probably something got to do with overflow but I canât figure out what. What am I missing?