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

×

WA :Maximize It

Problem : https://www.codechef.com/LTIME66B/problems/MXM

My Solution : https://www.codechef.com/viewsolution/21692278

Working well with most of my Testcases ; Please help !

asked 24 Nov '18, 22:39

prembharwani's gravatar image

2★prembharwani
195
accept rate: 0%


It does not work for the following simple test case:

1
5 2
1 1 3 3 8
Your code generates 3, while it should be 4.

The code has multitude of problems, starting with

        int n,k;
        char numbers[n+1];
        int sum=0,sum1=0,prod=1,fprod=1,res=0,p;
        cin>>n>>k;
        for(int i=0;i<n;i++){
            int num=1;
            cin>>p;
            for(int j=0;j<p;j++) {
                num=num*k;
            }
            numbers[i]=num;
        }
1. You define array numbers[n+1] at the moment when n is not properly initialized yet. 2. You store values of powers of p in char which is limited by 127.

What's the most interesting is that your code is still able to solve some of the test cases.

link

answered 24 Nov '18, 23:54

oleg_b's gravatar image

7★oleg_b
2174
accept rate: 18%

edited 24 Nov '18, 23:55

@oleg_b Thank You ! Even 'long long int' won't work for storing the values of the (integer)^(power) , Please correct me if I am wrong ?

(25 Nov '18, 07:14) prembharwani2★

Yes, 'long long int' does not have sufficient capacity. The approach should be quite different - you need to represent the numbers in the base of k. For example, if k is 10, then 10^100 is a vector with 101 elements, all of them are zeros, except the last one which is 1.

(25 Nov '18, 17:24) oleg_b7★
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,901
×539
×21
×20

question asked: 24 Nov '18, 22:39

question was seen: 218 times

last updated: 25 Nov '18, 17:25