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

×

WA in Maximum Number (MAXNUM3) LTIME53

Can someone give a test case where my code fails or rather guide me to the correct approach ?

Problem My solution

After taking care of the last digit cases, I'm using a greedy approach to find the first number that on removal will lead to (sum of digits) %3=0 and has the next number greater than itself. If such a number doesn't exist, I remove the lowest rightmost number that will lead to that result.

asked 28 Oct '17, 23:18

trijeet's gravatar image

6★trijeet
2355
accept rate: 25%


havent taken care of the case when last%2 == 0 and l2%2 == 0.

link

answered 28 Oct '17, 23:23

adhyyan1252's gravatar image

6★adhyyan1252
1425
accept rate: 11%

That's when the greedy approach is used.

(28 Oct '17, 23:26) trijeet6★

consider the case 3 960. the answer should be 96

(28 Oct '17, 23:27) adhyyan12526★

I applied the same technique, passed only subtask2.

Didn't understand where the approach is wrong. code

link

answered 28 Oct '17, 23:31

sachinbisht939's gravatar image

4★sachinbisht939
113
accept rate: 0%

In your code on line 73:
x < a[i+1]-'0' this condition is wrong because it doesn't guarantee that the resulting number after deleting a digit will be greater than the one you found earlier.

Consider this test case:
Input
2
668
663

Your Output
-1
66

Correct Output
66
66

link

answered 28 Oct '17, 23:34

a_d_i's gravatar image

2★a_d_i
1746
accept rate: 23%

edited 28 Oct '17, 23:34

Can anyone tell me due to which testcase it was showing wrong answer?

https://www.codechef.com/viewsolution/15992665

link

answered 29 Oct '17, 00:09

spp____'s gravatar image

2★spp____
1.1k211
accept rate: 7%

1

Input:
1
6666666666

Correct Output:
666666666

Your Output:

(29 Oct '17, 00:22) a_d_i2★

I'm noob in java so I can't help you with why your code gives no output but I can say that you've read the question wrong. I see you've taken input as integer which is wrong because the input constraint says that input number can be of 10^5 digits long i.e input number can be 10^(10^5) which your long int input can't handle. Try implementing using string.

Hope it helps.

(29 Oct '17, 00:27) a_d_i2★

thanks @a_d_i

(29 Oct '17, 00:28) spp____2★

You're welcome bro.

(29 Oct '17, 00:44) a_d_i2★

If you want another approach, Have a look here.

If you wannna find bug in your approach, explain it in a bit detail. :)

link

answered 29 Oct '17, 00:24

taran_1407's gravatar image

5★taran_1407
3.9k2387
accept rate: 22%

Can anyone give me a test case where my code fails? It's working well for all the test cases I checked.

PLEASE HELP ME!!!

I'm storing the digits in an array from one's place. Then I am iterating through all the digits and finding the new number by removing that particular digit. Now, I'm checking whether it is divisible by 6 or not and if it is then I check whether it is largest number possible which I initially set to -1. At last I'm printing the new number with k-1 digits where k is the total number of digits in the initial number. Leading zeros will be printed since I used %0*d and passed k-1 and maxnum to it. LINK:- My Solution

link

answered 29 Oct '17, 00:29

ramini's gravatar image

2★ramini
615
accept rate: 8%

edited 29 Oct '17, 00:35

It would time out.

The solution time complexity is O(N^2) which won't pass.

(29 Oct '17, 00:33) taran_14075★

Further, the number can have 10^5 digits, thus, can't be stored in int or even long long.

(29 Oct '17, 00:34) taran_14075★

But it's giving wrong answer

(29 Oct '17, 00:37) ramini2★

n can be 100000 so it can only have a maximum of 6 digits right?

(29 Oct '17, 00:38) ramini2★

n can have 100000 digits .

So you can't store it in int

(29 Oct '17, 00:38) spp____2★

But in constraints it is giving n>=2

(29 Oct '17, 00:39) ramini2★

Ok @ramini , your output for 66666666666666666 is coming -1 which is wrong

(29 Oct '17, 00:45) spp____2★

@spp___ There's no single digit input in this question. Read the constraints carefully.
2<= n <= 10^5

(29 Oct '17, 00:46) a_d_i2★

n= no.of digits the number has !!!!

(29 Oct '17, 00:50) soham12346★
showing 5 of 9 show all

Try the following:

333966 => 33966

369369 => 69369

123456 => 12456

123126 => 12312

654321 => 65421

162132 => 16212

167137 => 17137

137167 => 17167

link

answered 29 Oct '17, 04:09

djvdm123's gravatar image

3★djvdm123
734
accept rate: 0%

-1

why u define soo much macro's?

link

answered 28 Oct '17, 23:26

pramod_33's gravatar image

1★pramod_33
-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:

×1,056
×358
×64
×12

question asked: 28 Oct '17, 23:18

question was seen: 617 times

last updated: 29 Oct '17, 04:09