mokoto's blog

By mokoto, history, 7 months ago, In English,

Hello, my binary search approach for problem e is , suppose we had played x-1 round and currently at round x , we will check whether we can kill monter in that round x or not , if yes we shift high to curr round — 1 else low to curr round + 1 .

my low range query is = 2 , since i alredy checked for round 1 , trivially . and high range r = (h / abs(sum) ) +1. where sum is my vector sum .

But the approach is continuously giving WA at tc : 92 .

https://codeforces.com/contest/1141/submission/51547489

where my approach is wrong .

 
 
 
 
  • Vote: I like it
  • -12
  • Vote: I do not like it

»
7 months ago, # |
  Vote: I like it +5 Vote: I do not like it

Here's a tip to debug your code. Try asserting an invariant. Then, if you get runtime error, you will know where your logic fails.

  • »
    »
    7 months ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    thanks ltdt.. but its hard to debug using assert if u have type casting problem and ur code is correct on evry single smaller input.

    thanks for help .. LancetheDragonTrainer

»
7 months ago, # |
  Vote: I like it 0 Vote: I do not like it

Just a first thought: doesn't std::accumulate(iter, iter, int) return an int?

  • »
    »
    7 months ago, # ^ |
    Rev. 2   Vote: I like it 0 Vote: I do not like it

    Thank you very much mnbvmar

    i changed it to long long instead of using accumulator and it passed..

    i spent 2 hrs yesterday on debugging it.. you taught me a new thing where to use accumulator.. Thanks to you ... for the help..

    ac code

    • »
      »
      »
      7 months ago, # ^ |
        Vote: I like it 0 Vote: I do not like it

      you taught me a new thing never to use accumulator

      The lesson is not to avoid using accumulator but to know what you are doing. Doing CP doesn't entitle you to cut corners when learning a programming language.

      • »
        »
        »
        »
        7 months ago, # ^ |
        Rev. 2   Vote: I like it 0 Vote: I do not like it

        yaa.. thats also right i agree. .. thanks.. i changed never to where .. now its looks good :)

    • »
      »
      »
      7 months ago, # ^ |
        Vote: I like it +5 Vote: I do not like it

      You could as well replace long long sum = accumulate(v.begin() , v.end() , 0); by long long sum = accumulate(v.begin() , v.end() , 0ll); and it would work