Asterisk007's blog

By Asterisk007, history, 4 years ago, In English

Since I cant find the editorial i am asking my doubt here. my code to problem F

https://mirror.codeforces.com/contest/1729/problem/F

is repeatedly failing test case 7.

Here is my code for your reference:

https://mirror.codeforces.com/contest/1729/submission/172019259

thanks

  • Vote: I like it
  • 0
  • Vote: I do not like it

»
4 years ago, hide # |
Rev. 2  
Vote: I like it 0 Vote: I do not like it

you are trying to cast string to int with stoi() but the result is too large to represent it as integer. My local G++ 12.2.0 fails with std::out_of_range if i want to cast string '111...1' (length = 1000) to int with stoi() for example

»
4 years ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

string qq=s.substr(l-1,r-l+1); int j=stoi(qq);//here it is exceeding integer limit...

notice that you don't need to store the whole number in 'j' variable ...just store gg%9 in 'j'

but still it will give TLE you need to process all 'w' substrings and store the information in an double dimentional vector and later in queries you can use them in O(1) time :-)