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

×

How does Codechef test whether my solution is correct or not?

2
1

When I submit my code for a particular problem on CodeChef, who will test if my solution is correct or not? Can some one tell me how is my solution tested?

asked 21 Jun '12, 11:08

abhijeetpandey's gravatar image

3★abhijeetpandey ♦♦
45471013
accept rate: 22%


16

Your code is tested by a computer automatically, not by a human being, and you have to write your code accordingly.

For each problem, Codechef will have one or more input files, each according to the specifications mentioned in the problem statement, and corresponding correct output files. Codechef will run your program on each of the input files by redirecting the standard input stream to an input file, and the standard output stream to another file. The output generated by your program must match the correct output exactly in order to be judged correct.

Some consequences of this:

  • If your program starts by printing 'Enter the number' and the problem does not tell you to do so, then since this is not part of the correct output, you will be never be judged correct regardless of what the rest of your program does.

  • As all that matters is that the output files match, it makes no difference at all at what point in your program's execution that this output is written. So there is no need to read all of the input before starting output; it is much more common to just print out each result as you are reading through the input.

  • If you use any method other than using the standard input and output streams - for example, using command line arguments, reading from a file, opening up some sort of dialog box, or otherwise - you will never be judged correct.

link

answered 21 Jun '12, 11:10

admin's gravatar image

0★admin ♦♦
19.6k349497539
accept rate: 35%

I do not know who wrote it here (and I can't find it now), that tester ignores empty lines, is it correct?

(21 Jun '12, 20:11) betlista ♦♦3★

Any amount of whitespace is considered equivalent to any other amount of whitespace. If you are asked to print one space between answers, and print three returns, 2 spaces, 4 tabs, and a few extra \r characters, that makes no difference.

(22 Jun '12, 09:22) triplem ♦♦3★

include <stdio.h>

int main() { int t,i,n,p,r,c; scanf("%d\n",&t); for(i=0;i<t;i++) { scanf("%d\n",&n); p=0; c=0; while(n!=0) { r=n%10; c++; if(r==0) p++; n=n/10; } if((p==1) || (p==c-1)) printf("yes\n"); else printf("no\n"); } return 0; }

link

answered 15 Sep '16, 22:02

pbvkrishna's gravatar image

2★pbvkrishna
1
accept rate: 0%

import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.lang.reflect.Array; import java.util.Arrays;

class UncleJohny {

public static void main(String[] args) throws IOException {

    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    int N;

    int t = br.read();
    br.readLine();

    for (int i = 0; i < t; i++) {

        N = Integer.parseInt(br.readLine());
        String s1 = br.readLine();

        String s[] = s1.split(" ");
        int a[] = new int[N];
        for (int j = 0; j < N; j++) {

            a[j] = Integer.parseInt(s[j]);
        }
        int K = Integer.parseInt(br.readLine());
        int c = a[K - 1];
        Arrays.sort(a);

        for (int m = 0; m < N; m++) {

            if (a[m] == c) {
                System.out.println(m + 1);
                break;
            }
        }

    }

}

}

link

answered 11 Dec '16, 12:55

jyotigupta0707's gravatar image

1★jyotigupta0707
1
accept rate: 0%

include<stdio.h>

int main() { int c,d,l,i=0,j=0,k,f=0,t,p; int x[100000]; scanf("%d",&t); for(p=0;p<t;p++) {="" i="0,f=0,j=0;" scanf("%d%d%d",&c,&d,&l);="" if(c<="d)" k="c+1;" if(c="">d) k=2d; while(i<k) { if((4c+4*d)-j==l) { f=1; break; } i++; j=j+4; } if(f==1) x[p]=f; else x[p]=f; } for(p=0;p<t;p++) { if(x[p]==1) puts("yes"); else puts("no"); } return 0; }

link

answered 13 Jan '17, 19:17

chittresh's gravatar image

2★chittresh
2
accept rate: 0%

include<stdio.h>

include<malloc.h>

int gcd(int ,int ); int main(void) { int i=0,t,j=0,n,sum=0,flag=1,z=0; int a,result;

do{
scanf("%d",&t);
if(t>=1 && t<=200000)
{
    flag=0;
}
}while(flag);
z=t;

while(t--)
{
    flag=1;
    do{
        scanf("%d",&n);

        if(n>=1 && n<=1000000)
        {
            flag=0;
        }
}while(flag);
        sum=0;
a=(int *)malloc(n*sizeof(n));
result=(int *)malloc(t*sizeof(int));
for(i=1;i<=n;i++)
{
    for(j=i+1;j<=n;j++)
    {
        sum=sum+gcd(a[i],a[j]);
    }
}

result[t]=sum;
}

for(i=z;i>=1;i--)
{   printf("%d",result[i]); }
return 0;

} int gcd(int a,int b) { int r; do{ r=a%b; a=b; b=r; }while(r!=0); return a; }

link

answered 04 Mar '17, 23:54

squadron's gravatar image

1★squadron
1
accept rate: 0%

include <bits stdc++.h="">

using namespace std; void te() { int n; cin >> n; vector<string> s(n); for(int i = 0; i < n; ++i) cin >> s[i]; for(int i = 0; i < n; ++i) if(s[i] == "cookie") if(i == n - 1 || s[i+1] == "cookie") { puts("NO"); return; } puts("YES"); } int main() { int T; cin >> T; while(T--) te(); }

link

answered 20 Mar '17, 15:21

nbatra's gravatar image

0★nbatra
1
accept rate: 0%

include<stdio.h>

include<math.h>

int main() { unsigned long int n,count,s,a=0,k; scanf("%lu %lu",&n,&k); if(n<=pow(10,7)&&k<=pow(10,7)) { while(a<n) { scanf("%ld",&s); if(s<=pow(10,9)&&s%k==0) { count++; } a++;

}
    }
printf("%lu",count);
return 0;

}

link

answered 21 May '17, 16:06

ironcode123456's gravatar image

0★ironcode123456
1
accept rate: 0%

How do i get input and write output in PHP? I run code in IDE, it take 0,01s. But when i submit the code, i get "Time limit exceeded".

link

answered 21 May '17, 16:14

buihanh2304's gravatar image

0★buihanh2304
1
accept rate: 0%

Your code is correct or not is determined by test case writtern by problem setter or experienced competitive coder and reviewed by various other coder. When you submit your solution it feed specific input sets and test your output against its correct output files. Its all done in milliseconds by machine :);

link

answered 21 May '17, 16:29

girishkuniyal's gravatar image

1★girishkuniyal
1
accept rate: 0%

import java.util.Scanner; class SF{ public static void main (String[] arts){ Scanner s=new Scanner(System.in); int n=s.nextInt(); int a[]=new int[n]; int b[]=new int[n]; for(int i=0;i<n;i++) { a[i]=s.nextInt(); int f=1; for(int j=1;j<=a[i];j++) { f=f*j; } b[i]=f; } for(int i=0;i<n;i++) {System.out.println(b[i]);}}}

link

answered 02 Aug, 23:14

king_kk's gravatar image

2★king_kk
1
accept rate: 0%

import math T=int(input()) for i in range(T): N=int(input()) a=int(math.log2(N)) b=2a if N==2: print(1) elif N==1: print(2) elif b==N: print(1) else: c=N-b d=int(math.log2(c)) print(min(c-2d,2**(d+1)-c))

what is wrong in this code

link

answered 08 Aug, 18:15

ap628830's gravatar image

2★ap628830
1
accept rate: 0%

hii Do you send snack down code plese

link

answered 12 Oct, 21:53

zawed123's gravatar image

0★zawed123
1
accept rate: 0%

include <stdio.h>

int main() { int T; char name[100]; int count ,count1,i; scanf("%d",&T); for(i=0;i<T;i++) { scanf(" "); gets(name);

for(int j=0;name[j]!='\0';j++)
{
    if(name[j]=='R')
    {
        count1++;
    }
    else
    {
        count++;
    }
}

if(count1==count)
{
    printf("yes\n");
}
else
{
    printf("no");

}
count=0;
count1=0;

} return 0; }

link

answered 18 Nov, 23:22

vitthalpatidar's gravatar image

1★vitthalpatidar
1
accept rate: 0%

-2

include<stdio.h>

include<math.h>

long long int prime(long long int ); long long int sum_factor(long long int );

long long int prime_no(long long int p) { long long int h; for(h=2;h<p;h++) { if(p%h==0) { break; } } if(h==p) return(p); else return(0); }

int main() { long long int t,l,r,i,d,b;

scanf("%lld",&t);
while(t--)
{
    long long int sum=0;

     for(i=l;i<=r;i++)
     {
        b=2;
        d=1;
        do
        {
            d=pow(b,2);
            if(i%d==0)
            {
                d=0;
                 break;
            }
            b=b+1;

        }while(i>=d);

        if(d==0)
            continue;
        else
        {
            sum+=sum_factor(i);

        }

     }
    printf("%lld\n",sum);
}
return 0;

}

long long int prime(long long int a)

{ long long int s[a],y=0,k,m,c=0;

for(k=2;k<=a;k++)
{
    m=prime_no(k);
    if(m>0)
    {

        s[y]=m;
        y++;
    }
}
for(k=0;k<y;k++)
{
    if(a%s[k]==0)
    {
        c++;
    }
}

c=prime_no(c);

if(c>0)
    return (a);
else
    return (0);

}

long long int sum_factor(long long int x)

{ long long int sm,j,res; sm=0; for(j=1;j<=x;j++) { if(x%j==0) { sm+=j; } }

res=prime(sm);
return (res);

}

link

answered 24 Jun '16, 17:51

deepak2016's gravatar image

4★deepak2016
472
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:

×243
×206
×196

question asked: 21 Jun '12, 11:08

question was seen: 48,499 times

last updated: 18 Nov, 23:22