You are not logged in. Please login at www.codechef.com to post your questions!

×

Runtime error in code

link to question : http://codeforces.com/contest/817/problem/B

link to solution : http://codeforces.com/contest/817/submission/27807533

Getting runtime error on 5th test case .

Can't figure out why?

asked 16 Jun '17, 15:24

chunky_2808's gravatar image

3★chunky_2808
1649
accept rate: 4%


You are storing frequencies in the arr2 and array elements can be upto 10^9.So you can't use an array to store frequencies and instead of arrays you should use map to store frequencies.

here is my accepted solution and if you have any doubt,please comment. http://codeforces.com/contest/817/submission/27798017

link

answered 16 Jun '17, 15:35

hruday968's gravatar image

4★hruday968
1.7k210
accept rate: 14%

edited 16 Jun '17, 15:42

1

Got AC using Map Thanks!!

(16 Jun '17, 15:44) chunky_28083★

Since the input array has elements of the order 10^9, you invoke index out of bounds by writing arr2[arr[b]]++.

In the case where you get the runtime error, each arr[i] is 10^9 and the size of arr2 is 10^5. Hence the index out of bounds.

link

answered 16 Jun '17, 15:39

zeeshan_ju's gravatar image

4★zeeshan_ju
1
accept rate: 0%

toggle preview
Preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported
  • mathemetical formulas in Latex between $ symbol

Question tags:

×672
×531

question asked: 16 Jun '17, 15:24

question was seen: 325 times

last updated: 16 Jun '17, 15:44