Rating changes for last rounds are temporarily rolled back. They will be returned soon. ×

 
 
 
 
General
 
 
# Author Problem Lang Verdict Time Memory Sent Judged  
189932338 Practice:
sajid_knownas_hawk
1762A - 25 GNU C11 Wrong answer on test 1 15 ms 0 KB 2023-01-21 10:58:24 2023-01-21 10:58:24
→ Source
//codeforces problem link: https://codeforces.com/contest/1762/problem/A
// Divide and Conquer
//my alogorithm:
// We are asked to find least amount steps that is required to make 
//an array good(sum is even). I took the lowset number in the array and tried
//to divide it by 2(according to question) and then do the sum again until we find 
//the sum as an even number. Thus we will get the least required steps.

//To-do:
//1. I need to find a way to 
//divide one number and divide the result repeatedly by 2
#include<stdio.h>
int main()
{
    int t,n,a[55],sum=0,save,desum,p,q,r=2,l,ct=0,i=0; 
    // variable declaration: 
    /* t=test cases,n=number of element in each array a,sum=sum of the array,save=used in bubble sort
    q=smallest number of the array,p=used to store the value of new element of the array
     after dividing it by r=2,
    desum=(sum of the whole array-smallest element)*/
    printf("test cases: ");
    scanf("%d",&t);

    for(int m=1;m<=t;m++) // test case loop
    {  
        printf("array elements:  ");
        scanf("%d",&n); 
        for(int i=0;i<n;i++)
        {
            scanf("%d",&a[i]);
            sum=sum+a[i];
        }
        
        if(sum%2==0)
        {
          printf("0\n");
        }
        else if(n==1)
        {
            q=a[0];
         for(int i=1;i<=99;i++)
        {
         
                
                r=2;
                p=q/r;
                desum=p;
                q=p;
                ct++;
                 printf("t#%d : desum=%d\n ",i,desum);
                
                if(desum%2==0 || desum==0 || desum<0)
               {
                 printf("Result: %d\n",ct);
                 ct=0;
                 goto end;
               }        
        }
        }
        else 
        {
            
            for(int i=0;i<n;i++)
            {
                for(int j=i+1;j<n;j++)
                {
                    if(a[i]>a[j])
                    {
                        save=a[j];
                        a[j]=a[i];
                        a[i]=save;
                        
                    }
                }
            }
            
           // had issues with algorithm
           q=a[0]; // q being the smallest number
           printf("lowest element: %d\n",q);
           if(n==1)
           goto one;
           sum=sum-q;
           printf("check step:\n sum:%d\n",sum);
           one:;
           for(l=1;l<=99;l++)  // we got q=the smallest number.
           {  
               
            p=q/r; 
            desum=sum+p;
            q=p;
        
            ct++;
            printf("t#%d : desum=%d \n q now: %d \n",l,desum,q);


              /*  r=l*2;
               p = q/r;
               desum=sum+p;
               ct=ct+1; */
               if(desum%2==0 || desum==0)
               {

                 printf("Result : %d\n",ct);
                 ct=0;
                 goto end;
               }
           }
        }     
       end:;
       sum=0;
       desum=0;
       q=0;
    }
    return 0;
}
// Sajid ~ 21 Jan,23; 1:52PM
?
Time: ? ms, memory: ? KB
Verdict: ?
Input
?
Participant's output
?
Jury's answer
?
Checker comment
?
Diagnostics
?
Click to see test details