CodeChef is a non-commercial competitive programming community
Login
Username (New User? Signup) Password (Forgot Password?)
Signup
Login or
Signup with
Connect
Note
  • Publicize your achievements on your Facebook Wall.
  • Challenge your friends or ask them for help.

Site Navigation

  • PRACTICE
    • Easy
    • Medium
    • Hard
    • Challenge
    • Peer
  • COMPETE
    • February Long Contest
    • January CookOff
    • January Long Contest
  • DISCUSS
    • Wiki
    • Forums
    • Blog
    • Twitter
  • COMMUNITY
    • CodeChef Meetups
    • Campus Chapters
    • Host your Contest
    • User Groups
    • CodeChef TechTalks
    • All Educational Initiatives
    • Event Calendar
  • HELP
    • Frequently Asked Questions
    • FAQ for problem setters
    • Problem Setting
    • Ranks
    • Tutorials
  • ABOUT
    • About CodeChef
    • Team CodeChef
    • Press Room
    • CodeChef Financials
    • CodeChef Sponsorships
    • CEO's Corner
    • Contact Us
    • About Directi
Home » Practice(easy) » Enormous Input Test

Enormous Input Test

Problem code: INTEST

  • Submit
  • All Submissions

All submissions for this problem are available.

The purpose of this problem is to verify whether the method you are using to read input data is sufficiently fast to handle problems branded with the enormous Input/Output warning. You are expected to be able to process at least 2.5MB of input data per second at runtime.

Input

The input begins with two positive integers n k (n, k<=107). The next n lines of input contain one positive integer ti, not greater than 109, each.

Output

Write a single integer to output, denoting how many integers ti are divisible by k.

Example

Input:
7 3
1
51
966369
7
9
999996
11

Output:
4

Date: 2008-12-01
Time limit: 8s
Source limit: 50000
Languages: C C99 strict C++ PAS gpc PAS fpc JAVA NICE JAR C# C#2 NEM ST ASM D FORT ADA BASH PERL PYTH RUBY LUA ICON PIKE PHP SCM guile SCM qobi LISP sbcl LISP clisp HASK CAML CLPS PRLG WSPC BF ICK TEXT


  • Submit

Comments

  • Login or Register to post a comment.

vprajan @ 16 May 2009 06:12 AM

a small python script to generate a sample input to this program:

import os
import random

f = open("sample.txt","w")
lineno=random.randint(0,1000000)
divisor=random.randint(0,10000000)
f.write(str(lineno) " " str(divisor) "\n")
for i in range(0,lineno):
f.write(str(random.randint(0,1000000000)) "\n")
f.close()

This might help :)

sid_chilling @ 17 May 2009 05:23 AM

Hi I need help on this problem. My Java program times out. As solutions of this problem are not available I am unable to find how to optimise my approach. Here is my code. Please tell me how to improvise. I think this is the main problem why my other programs are also getting timed out.

import java.util.*;
public class Main {
public static void main(String[] args){
Scanner sc=new Scanner(System.in);//to read from input console
int n=sc.nextInt();
int k=sc.nextInt();
int res=0; //the result
for(int i=0;i

sid_chilling @ 17 May 2009 05:24 AM

for(int i=0;i

sid_chilling @ 17 May 2009 05:24 AM

Why is my comment getting truncated?

kyun @ 19 May 2009 11:33 PM

@Siddharth Saha

As no one has replied, I think whats happening is that your next term is '' sign. I think there might be a way to escape the same. Or use the main forums. They have [code][/code] tags I think.

kyun @ 19 May 2009 11:34 PM

Hehe, I did it too. I mean the (less than) sign. Being mistaken for html/xml tags

tojochacko @ 20 May 2009 01:31 AM

@Siddharth Saha: the problem has been solved, now u can post ur code without it getting truncated.

prasanna @ 10 Jun 2009 03:09 AM

y i am getting time limit excedded?

leppyr64 @ 10 Jun 2009 06:06 AM

@prasanna: that's the difference between scanf/printf and cin/cout.

hrj @ 3 Jul 2009 02:23 AM

My scala program given a test with n = 10^6 runs under 3 seconds on my laptop (Core 2 Duo, 1.6Ghz)

Why would it timeout on your servers?

dragonair @ 5 Jul 2009 04:40 AM

i did at once ;)

sid_chilling @ 5 Jul 2009 05:12 AM

can we not look at other people's solutions to this problem?

i0exception @ 6 Jul 2009 05:11 PM

@siddharth This is under consideration.

delta @ 14 Jul 2009 08:14 PM

Would love to see the optimized solutions to this problem.

admin 2 @ 14 Jul 2009 08:20 PM

solutions for this problem are now public...

calvin @ 15 Jul 2009 09:05 PM

my program works fine on vs 2005, but here it is giving compilation err...any ideas?

delta @ 15 Jul 2009 11:36 PM

I must appreciate the effort MS has put into optimizing the performance of their Console IO classes. Its awesome how no one has come close to beating the straightforward C# code for this problem.

as6485 @ 19 Jul 2009 08:16 PM

The fastest solutions in C/C use the fread( ) function.... But alas this function has known upstream bug and as such is not working properly in my specs OpenSuse 11.1, gcc 4.3.2, P4 2.8Ghz.... Though I know the gcc version is higher in my case than the Online judge system... but the code is perfectly ANSI compliant... Some are resorting to use fgets( ) and such string functions but they are not as fast as fread( )

spike @ 10 Aug 2009 09:09 AM

LoL. I made it first try with 7.92 seconds. (8 second time limit.)

ashfame @ 13 Aug 2009 11:16 PM

I am getting a compiler error on submission but I can run the same with the correct output on my desktop http://www.codechef.com/viewsolution/70027/
Any pointers?

admin 2 @ 13 Aug 2009 11:21 PM

Please don't use conio.h. Read the faq at http://blog.codechef.com/2009/06/29/frequently-asked-questions/ for more information and http://www.codechef.com/help for sample source code in your language.

nighthunter33 @ 14 Aug 2009 02:51 AM

Hi all I need help on this problem too, I can't figure out why I'm getting a runtime error for me code, it runs fine when i compile it, what am i missing?

leppyr64 @ 14 Aug 2009 05:00 AM

10^7 > 1000000

nighthunter33 @ 14 Aug 2009 06:09 AM

if i size my array to 10^7 the program crashes, is there another way to size it besides just typing in 10000000

admin 2 @ 14 Aug 2009 06:33 AM

Your code crashes because you are declaring the entire array inside your main function, and as a result on the stack. Declare it as a global variable. It won't crash then.

nighthunter33 @ 14 Aug 2009 08:38 AM

Ok thanks, I changed the type to static and it runs and complies but now receive a "wrong answer" even though all of the test cases ive run seem to work? Does anyone see a case that would cause it to fail?

vikas_singla86 @ 17 Aug 2009 07:21 PM

http://www.codechef.com/viewsolution/18435/ ..... successfully submitted code is same as mine .... it shows time exceeds ... any suggestions?

vikas_singla86 @ 17 Aug 2009 07:25 PM

http://www.codechef.com/viewsolution/72328/ ... this is correct link ... sorry for the mistake.

admin 2 @ 17 Aug 2009 07:41 PM

@bob All submissions are available for this problem. You can test your code on random inputs and verify your results with an accepted solution.

It is surprising to see that

shashidhar.msk @ 20 Aug 2009 10:52 PM
It is surprising to see that the code written in c++ gave a time-limit exceeded reply, where as the same code, after changing cout and cin to printf and scanf gave the answer is correct. Any reliable reason?? Provide different cases with which the problem is tested against in examples. The programs can be tested with our compilers and then be submitted. This is particularly because for one problem i'v solved(not easy category) has output in tune with the output given for the example cases. But gave reply "wrong answer".

cin and cout are very slow,

triplem @ 21 Aug 2009 06:59 AM
cin and cout are very slow, you should never use them.

cin and cout are on an

admin @ 21 Aug 2009 01:08 PM

cin and cout are on an average 3 times(personal opinion) slower compared to printf() and scanf(). You should avoid using cin and cout.

How do I find the score/time

kOrc @ 25 Aug 2009 12:33 PM
How do I find the score/time for my successful submission? The my submission page always shows an error.

If the submission page shows

admin @ 25 Aug 2009 01:21 PM

If the submission page shows an error, then your solution is not successful.

#include int main(void) {

capt @ 31 Aug 2009 09:27 PM
#include int main(void) { int size,i=0,ans=0; long number; std::cin>>size; std::cin>>number; long p; while(size>0) { std::cin>>p; size--; if(p%number==0) ans++; } std::cout<

http://codepad.org/UFm6O4s1

capt @ 31 Aug 2009 09:57 PM
http://codepad.org/UFm6O4s1 getting time limit exceeded ....... help , please!

Don't use cin and cout. Read

admin @ 31 Aug 2009 10:03 PM

Don't use cin and cout. Read the comments above for more information.

Hi I am new to this.Please

mocankit @ 8 Sep 2009 10:26 PM

Hi I am new to this.Please help me as to where to post the code and the language preference

For language preference, you

admin @ 9 Sep 2009 02:14 PM

For language preference, you need to make the change in your profile. For submitting code, click on the submit button on the top right corner of any problem and you will get a text box where you can submit the source code.

These people don't use Visual

vsha041 @ 4 Oct 2009 05:07 AM

These people don't use Visual Studio 2008 for compiling C++ / C# programs I suppose. It somehow gave compilation error for scanf_s ! I changed it to scanf and then it worked. They need to use latest technology and also give support for Boost and other third party libraries like Google Code Jam etc.

I'm afraid it's you who needs

triplem @ 4 Oct 2009 06:26 AM

I'm afraid it's you who needs to user proper technology :P scanf_s is NOT part of the ANSI standard; it is a Microsoft-only function which you should not be using.

is the source limit in

sushilnath @ 8 Oct 2009 09:00 PM

is the source limit in problems denote memory limit in MB

It is in bytes.

admin @ 8 Oct 2009 09:17 PM

It is in bytes.

I'm a bit confused -- I

bsdlogical @ 17 Oct 2009 01:18 PM

I'm a bit confused -- I submitted a solution that was marked as correct within a few seconds of submitting. That means it worked within the 8 second confine. However, when I look at "My Submissions", the time shows up as 17.66. Why is there such a discrepancy?

Are you sure you were told

triplem @ 17 Oct 2009 01:39 PM

Are you sure you were told correct answer within a few seconds of submitting? I doubt you would be able to get your solution done in only a few seconds, it would have taken the 17.66 seconds as stated.

I think you're right, it was

bsdlogical @ 17 Oct 2009 01:45 PM

I think you're right, it was probably longer than that. Nonetheless, 17.66 seconds is quite more than 8 seconds, and is even greater than twice 8 (http://blog.codechef.com/2009/04/01/announcing-time-limits-based-on-prog...). That's what confuses me.

That is what the FAQ is for

triplem @ 17 Oct 2009 01:46 PM

That is what the FAQ is for ;)

Perfect, thanks!

bsdlogical @ 17 Oct 2009 01:50 PM

Perfect, thanks!

  can you plz explain as to

rahulgolwalkar @ 19 Oct 2009 03:08 PM

 

can you plz explain as to why simple scanf() function wont work here ..

that we have to resort to fread() and make it complicated?

thnx..

and is there any way that i can subscribe to this thread so that i get notified when some one replies  ... so that i dont have to keep checking this thread..

thnx

 

  can you plz explain as to

rahulgolwalkar @ 19 Oct 2009 03:08 PM

 

can you plz explain as to why simple scanf() function wont work here ..

that we have to resort to fread() and make it complicated?

thnx..

and is there any way that i can subscribe to this thread so that i get notified when some one replies  ... so that i dont have to keep checking this thread..

thnx

 

scanf() and printf() work

admin @ 19 Oct 2009 03:48 PM

scanf() and printf() work here. Take a look at http://www.codechef.com/viewsolution/112280

plz chk my

Game_Bit @ 20 Oct 2009 11:41 PM

plz chk my solution

http://www.codechef.com/viewsolution/112948

see the point which i dont get is u dont have to do much in this prob take 2 int........

and thats i m doing ders no algo srt f thng in this prob then why my C++

solutionn takes time 5.43s and 2.6 M I am actually shocked to see the diff in best time and my time ......

kindly explain........

 

As the title suggests, this

admin @ 21 Oct 2009 01:04 AM

As the title suggests, this is a problem which tests th efficiency of your input / output routines. The difference between the time limits is mainly because the ones with a low time limit are using highly optimized I/O routines while you are using printf() and scanf()

very strange... allocating an

jcomeau_ictx @ 21 Oct 2009 10:03 AM

very strange... allocating an int array the size of the expected inputs speeded up my program from 8 seconds to .14 seconds, almost 60 times faster, WITHOUT EVEN USING the allocated structure. that's using the c# compiler, not c#2.

well i saw the best c++

Game_Bit @ 21 Oct 2009 10:39 PM

well i saw the best c++ solution few thngs arent clearand have some queries

1) why SZ 30000 whynot 50k or 90k how did u approximate?

2)in my case what i was doing was reading 1 input at a time and displaying the output the other solution takes the entire input stores in a buffer and calculates how do you differentiate the 2 solutions in terms of runtime and resource usage

3)is sscanf faster than scanf

4)do we have sth in addition to fread to do the similar job

 

thanks!

tarzan keep getting result

jcomeau_ictx @ 22 Oct 2009 01:23 AM

tarzan keep getting result from nasm program "wrong answer". tarzan don't know why. tarzan want to throw laptop against nearest rock.

You could try read()

admin @ 22 Oct 2009 03:03 AM

You could try read()

tarzan solve problem with

jcomeau_ictx @ 24 Oct 2009 08:48 AM

tarzan solve problem with tsort, and it also solve this problem. glad he not break computer. life is good.

Things are really easy in PHP

arjundevane @ 26 Oct 2009 08:30 AM

Things are really easy in PHP for formatting text and casting from 1 data type to another...

I worked this problem in one trial. I had thought it will take me 10-20 trials, because I had bad track record regarding I/O format errors.

fscanf(STDIN,"%s %s",$linemax,$div);
$linemax = intval($linemax);
$div = intval($div);
$lineno = 0;
$total = 0;
while($lineno < $linemax)
{
$num = fgets(STDIN);
if($num % $div == 0)
{
$total++;
}
$lineno++;
}
echo $total."n";

See!! Isnt that easy??

well can any1 plz resolve my

Game_Bit @ 26 Oct 2009 04:22 PM

well can any1 plz resolve my queries!!!!!!!!

Reading all input at once and

admin @ 26 Oct 2009 04:27 PM

Reading all input at once and then processing it would be faster. Especially if you are reading in memory in chunks. sscanf and scanf are used in different scenarios, you can't compare the two. You can use read() instead of fread()

#include <iostream>#include

shreydutta.28 @ 1 Nov 2009 08:10 PM


#include <iostream>
#include <cstdio>
int main(void) {
unsigned int count=0,i=0;
long unsigned int k,n;
unsigned int temp;
fscanf(stdin,"%uld",&n);
fscanf(stdin,"%uld",&k);
if(k<=10000000){
                while(i<n && std::cin>>temp && temp<=1000000000){
                           if(temp%k==0)count++;
                           i++;
                }
               }
std::cout<<count;               
return 0;
}

CAN ANYONE PLEASE EXPLAIN ME.....WHATS WRONG WITH....THIS CODE......WHY..ITS....SHOWING.....TIME LIMIT EXCEEDED.....

PLZ EXPLAIN ME...........

#include <iostream>#include

shreydutta.28 @ 2 Nov 2009 01:46 AM

#include <iostream>
#include <cstdio>
int main() {
unsigned count=0,i=0;
long unsigned k,n;
unsigned temp;
fscanf(stdin,"%ul",&n);
fscanf(stdin,"%ul",&k);
while(i<n && std::cin>>temp ){
            if(temp%k==0)count++;
            i++;
           }
std::cout<<count;               
return 0;
}

Y NO ONE IS REPLYING ME..................

N WHATS WRONG WITH THIS ONE ....STILL TIME LIMIT EXCEEDS...........

PLZ REPLY ME,,,,,,,,,,,,......////////

cin / cout are far too slow

triplem @ 2 Nov 2009 02:06 AM

cin / cout are far too slow to solve this problem.

Man..., y this is

shreydutta.28 @ 2 Nov 2009 07:10 AM

Man..., y this is so...........?

can i get the proper reason.........?

plz...............

What do you mean? That is the

triplem @ 2 Nov 2009 07:34 AM

What do you mean? That is the proper reason. cin and cout are very slow at reading/writing. You should use printf or scanf which are much faster, or write your own input routines using things like fread().

#include <iostream>#include

shreydutta.28 @ 3 Nov 2009 06:14 AM

#include <iostream>
#include <cstdio>
int main() {
unsigned count=0,i=0;
long unsigned int k,n,temp;
char str[16];
fscanf(stdin,"%ul",&n);
fscanf(stdin,"%ul",&k);
while(i<n && std::cin.ignore() && std::cin.get(str,16)){
            temp = 0;
            for(int j=0;j<std::cin.gcount();j++)temp = temp*10+(str[j]-48);
            if(temp%k==0)count++;
            i++;
           }
std::cout<<count;               
return 0;
}

this code shows the same output for the test case given above n others too which i tried.....but..chef...telling..wrong.ans.....

 

Can any one eXplain..........................

@Stephen Merriman thanks

shreydutta.28 @ 3 Nov 2009 06:16 AM

@Stephen Merriman

thanks man....i got..it...bt..help..me...with..the..previous..comment

I keep getting the status

13151-1 @ 10 Nov 2009 03:11 AM

I keep getting the status message for a successful submission but am reported with the following error :( internal error occurred in the system. Also at the same time while I check the recent activities, I find my code submitted under somebody else's name. Just to verify, I gave some variables some name I choose often, and I found the same code under somebosy else's name.

can some why does this code

snigdha @ 3 Dec 2009 09:30 PM

can some why does this code give a time limit exceeded??

#include<stdio.h>
int main()
{ 
    long n,k,x; 
    int cnt; 
    scanf("%ld",&n); 
    scanf("%ld",&k); 
    while(n>0) 
    {  
         scanf("%ld",&x);  
         if(x%k==0)  
         {   
             cnt++;  
         } 
    } 
    printf("%d",cnt);  
}

Because your while loop will

triplem @ 4 Dec 2009 01:59 AM

Because your while loop will never end?

The fastest C solution

iceman @ 7 Dec 2009 10:48 PM

The fastest C solution (gauravgaba) is ripped various times by other contestants. I understand that this is not a competition problem but it still is plagiarism. Admins please take not and take appropriate action.

@Aniruddha... Aniruddha

magiclko @ 15 Dec 2009 04:01 PM

@Aniruddha...

Aniruddha (Codechef) - 26th Oct,2009 16:27:23.

Reading all input at once and then processing it would be faster. Especially if you are reading in memory in chunks. sscanf and scanf are used in different scenarios, you can't compare the two. You can use read() instead of fread()

 

 

can you tell me which case would be faster

processing the input as i get it or first get all inputs and then do calculations?? reason i m asking again is that i did same as in case-2 in some another problem and surprisinngly it was slower..Or it depends on the situation?? if yes then do elaborate..^_^

$n=<STDIN>; $k=<STDIN>; $cnt

Anirudh_s @ 21 Dec 2009 04:55 PM

$n=<STDIN>;

$k=<STDIN>;

$cnt=0;

for ($i =0 ; $i< $n ; $i ++)

{

if(<STDIN>% $ k ==0)

{$cnt++;} }

print $cnt;

 

am getting wrong answer .....can anyone pls help?

I dont know the problem with

siddharthdevilz @ 29 Dec 2009 12:06 AM

I dont know the problem with my code. I checked other solutions and mine should work but it is timing out.... pls help.

#include <iostream>
using namespace std;
int main()
{
long n,k;
long t,count=0;
cin>>n>>k;
for(long i=0;i<n;i++)
{
cin>>t;
if(t%k==0)
count++;
}
cout<<count;
return 0;
}

Read the rest of the

triplem @ 29 Dec 2009 02:45 AM

Read the rest of the comments.

Am I not using the

saurajit11 @ 11 Jan 2010 07:17 PM

Am I not using the int_fast32_t types defined in stdint.h correctly?

My code is successful but very slow using regular printf/scanf and long, but the same code with int_fast32_t type gives wrong answer.

http://www.codechef.com/viewsolution/164482

Any ideas?

thanks guys, for telling me

neeraj_kumar6801 @ 23 Jan 2010 03:42 PM

thanks guys, for telling me the practical application of space time trade off.although i read about it in theory but the fact that cin and cout are so slow as compared to scanf and printf has come as a shock to me.....

the general thinking is that latest is the best but this fact has told me that old can also be gold.

Hi,   Shouldn't k strictly

vikaasgoel.007 @ 2 Feb 2010 12:33 AM

Hi,

 

Shouldn't k strictly greater than 0. i.e. (k>0)&&(k<=10000000)

a = int(raw_input('enter the

adityacs @ 8 Feb 2010 09:56 PM

a = int(raw_input('enter the value of a: '))
b = int(raw_input('enter the value of b: '))
c = []
for i in range(a):
d = int(raw_input('enter the value of d: '))
c.append(d)
for i in range(a):
if c[i] % b == 0:   
e = i + 1
print e

 

hey can anyone please tell me what is wrong in this program.I am getting run time error

hi' I try to write tis in

zack @ 13 Feb 2010 10:00 PM

hi' I try to write tis in java, and I  try to create a loop to read all the text from the screen (exept the first line). No matter what I do, the loop never finishes. I don't think it go's on all the time, It probobly just block waiting for more input, but I can't find a way to prevent it. Here is some of what I tryed.

 

do{
div = in.nextInt();
if (div % k == 0) count++;
}while (div > 0);

do{
div = in.nextInt();
if (div % k == 0) count++;
s = in.next();
}while (s != null);

while (in.hasNextLine()){
div = in.nextInt();
if (div % k == 0) count++;
}

About my last one - I was

zack @ 13 Feb 2010 10:35 PM

About my last one - I was mistaking in understanding what should be done. nevermind.

 

I submitted these two solutions witch exceeded 1 sec. Now I can't see how much each one took to run, wich could probobly help me. Can anyone help me find out witch one is better and what else can I improve?

 

import java.util.Scanner;
/**
*
* @author zack
*/
public class Main {

/**
* @param args the command line arguments
*/
public static void main(String[] args) {
Scanner in = new Scanner (System.in);
int n = in.nextInt(), k = in.nextInt(), count=0;
while (n > 0){
if (in.nextInt() % k == 0) count++;
n--;
}
System.out.println(count);
}
}

 

======================================================================================

 

import java.util.Scanner;
/**
*
* @author zack
*/
public class Main {

/**
* @param args the command line arguments
*/
public static void main(String[] args) {
Scanner in = new Scanner (System.in);
int n = in.nextInt(), k = in.nextInt(), count=0;
for (int i=0; i<n; i++) if (in.nextInt() % k == 0) count++;
System.out.println(count);
}
}

Now I see that the time limit

zack @ 13 Feb 2010 10:37 PM

Now I see that the time limit is 8 seconds. Is it true? My code did 1 sec on my laptop with netbeans. How come it does more than 8 seconds on the site?!

I highly doubt it takes 1

triplem @ 14 Feb 2010 02:11 AM

I highly doubt it takes 1 second on your laptop in the worst possible case. You are probably just testing your code on something simple. On a large input your code is taking 33 seconds on my computer.

Also, please read the FAQ before making comments.

Can anyone tell me that will

ankitagarwal9871 @ 3 Mar 2010 10:32 PM

Can anyone tell me that will i get the input from keyboard or from a text file?

Did you read the comment

triplem @ 4 Mar 2010 02:51 AM

Did you read the comment directly above yours?

can someone please tell me

edog @ 29 Mar 2010 01:19 AM

can someone please tell me what is wrong with this?? it gives runtime error on the online judge but it works on my computer:

http://www.codechef.com/viewsolution/216445

it is virtually the same thing as this, but this one does not give runtime error:

http://www.codechef.com/viewsolution/216442

plz help!

I wouldn't say that are

triplem @ 29 Mar 2010 05:47 AM

I wouldn't say that are virtually the same thing, they are completely different.

Have you tested your code on a maximal size input? Ie 10^7 integers, each equal to 10^9?

@stephen - thank you for your

edog @ 31 Mar 2010 10:02 AM

@stephen - thank you for your response.. it was very hopeful!

anyway, ive looked at a lot of your submissions and i really like your coding style! especially your use of vectors

i was also wondering whether putting something like int nums[1000000] inside main() would make the program slower than outside

*admin could you please

ace33 @ 14 May 2010 01:14 AM

*admin could you please remove my last two comments. thank you.

Hey all, I was just wondering if there was a way to run this program successfully in c++. I looked back through the submissions and count only find one that was accepted. I continue to receive a time out error, and was wondering if it was just a limit of C++ speed. My code is below.

<snip>

Please do not post code here.

triplem @ 14 May 2010 03:03 AM

Please do not post code here. Read the FAQ.

@ bob just try scanf in place

devendra088 @ 14 May 2010 07:12 PM

@ bob

just try scanf in place of cin .. and it will work fine within limit

use scanf/printf and avoid cin/cout

Anyone has an idea why C#

f03nix @ 14 May 2010 10:56 PM

Anyone has an idea why C# turns out to be the fastest here ?

I don't get it how seemingly

ChunChun @ 21 May 2010 11:36 PM

I don't get it how seemingly similar (though not necessarily congruent) solutions get a running time difference of the order of 10 ms..

man how are ANY of those

Dudio @ 5 Jun 2010 05:55 AM

man how are ANY of those numbers divisible by 10 million?  O_O

seriously wtf? Do you guys

Dudio @ 5 Jun 2010 06:01 AM

seriously wtf? Do you guys have a different understanding of what DIVISIBLE BY means or what? In the test solution, none of those numbers are divisible by k.

It would help if you read the

triplem @ 5 Jun 2010 06:47 AM

It would help if you read the section called 'input'. Where did you get the idea that k was 10 million? In the sample input, k is 3.

the problem is running

9arry @ 3 Jul 2010 02:10 AM

the problem is running perfectly on my system but it says runtime error wen i try to submit it...

wat shud i do???

im gettin a nzec runtime

9arry @ 3 Jul 2010 02:32 AM

im gettin a nzec runtime error in my program....wat shud i do???

can any one help me

v.vengadesh @ 17 Jul 2010 03:16 PM

can any one help me please...... its showing runtime errr....

#include<stdio.h>
main()
{
int a,b[10],c,i,j=0;
scanf("%d",&a);
scanf("n%d",&c);
for(i=0;i<a;i++)
{
scanf("%d",&b[i]);
if(b[i]%c==0)
j++;
}
printf("the count %d",j);
}

can any one help me

v.vengadesh @ 17 Jul 2010 03:18 PM

can any one help me please...... its showing runtime errr....

#include<stdio.h>
main()
{
int a,b[10],c,i,j=0;
scanf("%d",&a);
scanf("n%d",&c);
for(i=0;i<a;i++)
{
 scanf("%d",&b[i]);
if(b[i]%c==0)
j++;
}
printf("the count %d",j);
}

help me dude....

v.vengadesh @ 17 Jul 2010 03:25 PM

help me dude....

The problem statement tells

triplem @ 17 Jul 2010 04:28 PM

The problem statement tells you there could be 10000000 numbers in the input. You assume there are 10. Spot the difference :P

I used a simple printf/scanf

sanyal902 @ 18 Jul 2010 12:28 AM

I used a simple printf/scanf in my code and while the solution was correct,the time taken was about 5.5 seconds.

This compared to the solutions using arrays , took a considerable amount of time.

Could anyone explain this,since the array code certainly looks <!-- /* Font Definitions */ @font-face {font-family:Calibri; panose-1:2 15 5 2 2 2 4 3 2 4; mso-font-charset:0; mso-generic-font-family:swiss; mso-font-pitch:variable; mso-font-signature:-520092929 1073786111 9 0 415 0;} /* Style Definitions */ p.MsoNormal, li.MsoNormal, div.MsoNormal {mso-style-unhide:no; mso-style-qformat:yes; mso-style-parent:""; margin-top:0cm; margin-right:0cm; margin-bottom:10.0pt; margin-left:0cm; line-height:115%; mso-pagination:widow-orphan; font-size:11.0pt; font-family:"Calibri","sans-serif"; mso-ascii-font-family:Calibri; mso-ascii-theme-font:minor-latin; mso-fareast-font-family:Calibri; mso-fareast-theme-font:minor-latin; mso-hansi-font-family:Calibri; mso-hansi-theme-font:minor-latin; mso-bidi-font-family:"Times New Roman"; mso-bidi-theme-font:minor-bidi; mso-fareast-language:EN-US;} .MsoChpDefault {mso-style-type:export-only; mso-default-props:yes; font-family:"Calibri","sans-serif"; mso-ascii-font-family:Calibri; mso-ascii-theme-font:minor-latin; mso-fareast-font-family:Calibri; mso-fareast-theme-font:minor-latin; mso-hansi-font-family:Calibri; mso-hansi-theme-font:minor-latin; mso-bidi-font-family:"Times New Roman"; mso-bidi-theme-font:minor-bidi; mso-fareast-language:EN-US;} .MsoPapDefault {mso-style-type:export-only; margin-bottom:10.0pt; line-height:115%;} @page WordSection1 {size:595.3pt 841.9pt; margin:72.0pt 72.0pt 72.0pt 72.0pt; mso-header-margin:35.4pt; mso-footer-margin:35.4pt; mso-paper-source:0;} div.WordSection1 {page:WordSection1;} --> /* Style Definitions */ table.MsoNormalTable {mso-style-name:"Table Normal"; mso-tstyle-rowband-size:0; mso-tstyle-colband-size:0; mso-style-noshow:yes; mso-style-priority:99; mso-style-parent:""; mso-padding-alt:0cm 5.4pt 0cm 5.4pt; mso-para-margin-top:0cm; mso-para-margin-right:0cm; mso-para-margin-bottom:10.0pt; mso-para-margin-left:0cm; line-height:115%; mso-pagination:widow-orphan; font-size:11.0pt; font-family:"Calibri","sans-serif"; mso-ascii-font-family:Calibri; mso-ascii-theme-font:minor-latin; mso-hansi-font-family:Calibri; mso-hansi-theme-font:minor-latin; mso-bidi-font-family:"Times New Roman"; mso-bidi-theme-font:minor-bidi; mso-fareast-language:EN-US;} lengthier (yes,as lame as that sounds,bear with me-I'm a newbie).

And does this imply that using arrays/pointers makes programmes run faster ( in generall) ?

ok,something went wrong with

sanyal902 @ 18 Jul 2010 12:31 AM

ok,something went wrong with the last comment. I'll repeat-

does using arrays/pointers reduce runtime and if so-why?

I'm not entirely sure what

triplem @ 18 Jul 2010 04:18 AM

I'm not entirely sure what you are referring to by 'arrays', but scanf takes time in that it has to parse through your format string (even if it is only %d), and try to match that to something that occurs in the input. Since you know the format of the input already, reading it in bulk and parsing through it character by character grabbing the ints yourself is much faster.

i dont know why wrong

@mjad @ 25 Jul 2010 12:19 PM

i dont know why wrong ans

please help me

pleasessssssssssssssss




#include<stdio.h>



int main(void)

{

long long ks,d,n;

int c=0,i;

scanf("%I64d%I64d",&ks,&d);

for(i=0;i<ks;i++)

{

if(scanf("%I64d",&n)&&n%d==0)

c++;


}

printf("%I64dn",c);

return 0;

}


i dont know why wrong

rssvb @ 25 Jul 2010 09:12 PM

i dont know why wrong ans

please help me

pleasessssssssssssssss

 

 

 

Full Nulled Script English &

rssvb @ 25 Jul 2010 09:13 PM

Full Nulled Script English & Arabic Scripts

  #include<stdio.h> int

hemant1011 @ 10 Aug 2010 01:47 AM

 

#include<stdio.h>

int main()

{

unsigned long int times, num,div, count=0;

scanf("%lu %lu",&times, &div);

while(times--)

{

scanf("%lu",&num);

if(num%div == 0) count++;

}

printf("%lun",count);

}

 

Can anyone tell me what is wrong with this code, it runs perfectly fine on my system. Also unsigned long int is capable of storing values upto 10^9. Still it says runtime error when I submit the code.

 

FAQ

triplem @ 10 Aug 2010 02:59 AM

FAQ

How can I check the running

znarus @ 12 Aug 2010 01:35 AM

How can I check the running time of a program in Ubuntu linux?  There must be some simple way?

Never mind.. I found out.

znarus @ 15 Aug 2010 07:57 PM

Never mind.. I found out. It's the  'time' command .

When I browse 'successful

znarus @ 17 Aug 2010 07:29 PM

When I browse 'successful submission for this problem' I see for instance ' "user" 4.7M 47.83 RUBY ' . How can this be successful with a running time of 47.83 s  when the time limit is 8 s ?

FAQ

triplem @ 18 Aug 2010 02:25 AM

FAQ

Can someone give me reason

balajikandan @ 20 Aug 2010 01:56 AM

Can someone give me reason why my code is giving time exceed exception.

http://www.codechef.com/viewsolution/310170

This problem is designed to

triplem @ 20 Aug 2010 02:39 AM

This problem is designed to show how fast your input/output methods are. Scanner is an extremely slow way of reading input in Java.

I submitted the solution with

IttagoniK @ 22 Aug 2010 04:53 PM

I submitted the solution with a running time of 5.28s in C. While i looked at optimized solutions in C, i found usage of fread instead of scanf. Can someone explain how fread is faster than scanf? And i also noted when the SIZE of char array = 65536, run time is 0.48s. While i tried the same code with SIZE = 16 it gave me 1.36s

Please explain this... Thank you

scanf has to parse the format

triplem @ 23 Aug 2010 06:46 AM

scanf has to parse the format string and try to match %d to integers, %s to strings, etc. Doing this manually will save you a lot of time. In all cases, you don't want to have to read from the input file a huge number of times; instead you want to store results in a buffer then just look up the array each time, which is a lot faster.

why there is a runtime error

ashishrathi @ 25 Aug 2010 04:25 PM

why there is a runtime error for this code(Enormous Input Test):

 

#include<stdio.h>

int main()
{
long n, k, t, count=0, i;

scanf("%ld%ld",&n,&k);

for(i=0; i<n; i++)
{
scanf("%ld",&t);
if(k!=0 && (t%k)==0)
count++;
}
printf("%ld",count);

return 1;
}

The definition of runtime

triplem @ 25 Aug 2010 05:33 PM

The definition of runtime error is returning anything but 0 from your main method.

It says that there's NZEC

ashishrathi @ 26 Aug 2010 11:26 AM

It says that there's NZEC error..

But theres no stack overflow in my code.

pls help!

pls check this solution this

ni8mare @ 27 Aug 2010 12:00 PM

pls check this solution this gave compilation error ....

http://www.codechef.com/viewsolution/315083

its working fine

plz help me out.. how to

Pulkit_virgo @ 29 Aug 2010 04:40 AM

plz help me out.. how to solve this time limit exceeding issue in dis ques.. solution is in PERL

its takes 8 time even if i

kirtan @ 3 Sep 2010 01:36 PM

its takes 8 time even if i written same code as it shown here 0.14 ?

plz xplain me the quetion in

jravi96 @ 4 Sep 2010 07:32 PM

plz xplain me the quetion in simple language.

My solution was

manju10 @ 6 Sep 2010 06:42 PM

My solution was accepted.

This was the resulting scren.

Correct Answer

Execution Time: 5.46

But, what does the 5.46 mean ?

is it the worst case time ??


FAQ

triplem @ 7 Sep 2010 02:39 AM

FAQ

I just resubmitted the first

amirkg @ 21 Sep 2010 12:30 AM

I just resubmitted the first accepted submit in the list and it took 8 seconds but in the list it took 0.14 , Why?

@ashish what's exactly is the

killerdrummer @ 25 Sep 2010 11:48 AM

@ashish what's exactly is the error can u just let me know????

@amir u did it using colock

killerdrummer @ 25 Sep 2010 11:49 AM

@amir u did it using colock tick or so???

error occured in the internal

camphor @ 12 Oct 2010 08:33 PM

error occured in the internal system...wht does this mean....

my code is as follows...(its working on my system)

#include<stdio.h>
int main()
{
long i,x,y,n,count=0;
char s[2];
scanf("%s",&s);
x=s[0]-48;
y=s[1]-48;
for(i=0;i<x;i++)
{
scanf("%l",&n);
if(n%y==0)
count++;
}
printf("%l",count);
return 0;
}
pls tell me wht is ploblem with the code.....

  my piece of code but it is

sidcsevssut @ 18 Oct 2010 12:39 AM

 

my piece of code but it is showing time out error i dont understand why

import java.util.Scanner;

public class Main {

public static void main(String a[]){

Scanner sc=new Scanner(System.in);

int c=0,p,k,j;

k=sc.nextInt();

j=sc.nextInt();

sc.nextLine();

while(k>0){

p=sc.nextInt();

sc.nextLine();

if(p%j==0)           {

c=c+1;}

k=k-1;}

System.out.println(c);}}

 

As mentioned in the first

triplem @ 18 Oct 2010 01:33 AM

As mentioned in the first line of the problem, the purpose is to see if your input method is fast enough. Scanner is extremely slow, and therefore isn't.

can someone tell y this code

sweety14 @ 18 Oct 2010 11:34 PM

can someone tell y this code is wrong

#include<stdio.h>
main()
{
int n;
while(scanf("%d",&n)!=EOF)
{   
int k,i=0,j,counter=0;
scanf("%d",&k);
while(i<n)
{   
scanf("%d",&j);
if(j%k==0)
counter++;
i++;
}   
printf("%dn",counter);
}   
}

You seem to have been

triplem @ 19 Oct 2010 01:38 AM

You seem to have been accepted..

whenever im trying to submit

garfieldm89 @ 20 Oct 2010 02:24 AM

whenever im trying to submit the ans..it gives an error saying internal error occured in the system...is some thing wrong with my program or problem with the codechef server

direct1 admins....plz solve

garfieldm89 @ 20 Oct 2010 02:27 AM

direct1 admins....plz solve the prob of internal error in the system...many are not able to upload their solutions including me.

I get Time Limit exceeded for

tatevik_m @ 22 Oct 2010 05:41 PM

I get Time Limit exceeded for my every script.

Can anyone help me to optimize my script please?

Here is my script in BASH

 

read n k

while  ((n--)); do

read A
if  (( $(($A%$k)) == 0 ))
then
((sum++))
fi
done

echo ${sum-0}

I can't understand, why both

vintubr @ 28 Oct 2010 11:03 PM

I can't understand, why both the solutions below return Time limit Exceeded, if the second one is wrong, so the result should be: Wrong Answer.

First Solution:

====================================================================

inpList = raw_input().split();

print len([ 1 for n in xrange(0, int(inpList[0])) if input()%int(inpList[1])==0 ])

====================================================================

Second Solution:

====================================================================

inpList = raw_input().split();

print sum([ 2 for n in xrange(0, int(inpList[0])) if input()%int(inpList[1])==0 ])

====================================================================

Is it waiting something from my program or maybe the second did not return error because it was not even able to finish?

Thanks for your attention!

As the FAQ mentions, time

triplem @ 29 Oct 2010 01:54 AM

As the FAQ mentions, time limit exceeded means your program did not stop executing within the time limit. If it didn't stop running then of course there is no way for Codechef to determine whether it was correct or not :P

I can't succeed in getting my

axxyaan @ 30 Oct 2010 04:06 PM

I can't succeed in getting my scheme (guile) program to run this test in time. I find this a little odd. I have both a python and a scheme program. On my system the scheme program takes less time than 1.5 times the python program. The python program passes, the scheme program doesn't.

I read the FAQ that states that Python and Java, get double time and Ruby, PHP and Lisp get triple time. However no mentions of Scheme. I assumed that Scheme would get triple time because it is lisp-like, but with this result I am a bit doubtfull.

So could you tell me what the time limit factor is for Scheme?

Can someone tell me why this

hardfire @ 27 Nov 2010 07:06 PM

Can someone tell me why this gets TLE, nothing more can be done i think !!

 

int main ()

{

int n;

long k,num,cnt=0;

 

using std::cin;

using std::cout;

using std::endl;

 

cin >> n >> k;

while(n--)

{

cin>>num;

if(0==num %k)

cnt++;

}

cout << cnt << endl;

return 0;

}

The problem says the point of

triplem @ 28 Nov 2010 02:09 AM

The problem says the point of this problem is to show you whether your method of reading input/output is fast enough. As explained in the FAQ, cin and cout are very slow; this proves you should not be using them.

@admin sir plz check there

shazy @ 30 Nov 2010 03:22 PM

@admin

sir plz check there would be some problem in your compiler as it is showing time limit exceed everytime.

As my code is correct i don't know it is showing this.

we have checked your compiler by using already submitted solutions.It is also showing timit limit exceeded error,Plz explain How their problems are submitted earlier which are not submiited now.

I have posted a code in Java

akash_d_learner @ 2 Dec 2010 09:18 PM

I have posted a code in Java for this problem. Its time is 7.86 and memory is 177.77 . when i checked some other optimized solution then code was nearly same, but Time and memory were 0.0 each. Can you please tell me what got wrong in my code.

My Code:

import java.io.BufferedReader;

import java.io.InputStreamReader;

 

public class Main

{

public static void main(String args[]) throws Exception

{

int ans=0;

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

String line=br.readLine();

String words[]=line.split(" ");

int N=Integer.parseInt(words[0]);

int K=Integer.parseInt(words[1]);

while(N--!=0)

{

if(Integer.parseInt(br.readLine())%K==0)

ans++;

}

System.out.println(ans);

}

}

 

Other person Code:

import java.io.BufferedReader;

import java.io.InputStreamReader;

public class Main {

public static void main(String[] args) {

  1. BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
  2. try {
  3. String[] arrNK = br.readLine().split(" ");
  4. int n = Integer.parseInt(arrNK[0]);
  5. int k = Integer.parseInt(arrNK[1]);
  6. int count = 0;
  7. while(n>0) {
  8. if(Integer.parseInt(br.readLine())%k==0)
  9. count++;
  10. n--;
  11. }
  12. System.out.println(count);
  13. }
  14. catch(Exception e) {
  15. System.out.println(e.getMessage());
  16. }
  17. }
  18. }

I am sorry if Comparing of Code is not allowed. Please inform me if it is.

#include <iostream> using

neverserious @ 6 Dec 2010 12:34 PM

#include <iostream>

using namespace std;

int main()
{
    int n,k,t,count=0,f=0;
    cin >> n >> k;
    while(f++ < n)
    {
              cin >>t;
              t%k==0 ? count++ : count;
    }
    cout << count;
}

This code is giving time limit exceed. I checked with the submitted codes, to see if there is any better way of doing this,so I found this code.

  • #include<iostream>
  • using namespace std;
  •  
  • int main()
  • {
  • int No_no, Ran, In,counter=0,flag=0;
  • cin>>No_no>>Ran;
  • while(counter++ < No_no)
  • {
  • cin>>In;
  • ((In%Ran == 0)?flag++:flag );
  • }
  • cout<<flag;
  • }
  • Two codes are much same but one is accepted and one is giving time limit exceed.

    Any help is highly appreciated.

    got it by changing cin,cout

    neverserious @ 6 Dec 2010 12:41 PM

    got it by changing cin,cout to scanf and printf...but still unsure of why one of the above code is rejected and one is accepted

    Because, as already has been

    triplem @ 6 Dec 2010 02:01 PM

    Because, as already has been mentioned many times in these comments and also in the FAQ, this problem is about making sure your input/output methods are fast, and cin and cout are very slow.

    @Stephen: Both of Code in my

    akash_d_learner @ 8 Dec 2010 05:09 PM

    @Stephen: Both of Code in my post above r nearly same. Even then i am getting a lot of difference in time and memory. Please elaborate on this.

    0 time and memory can happen

    triplem @ 9 Dec 2010 02:27 AM

    0 time and memory can happen occasionally due to a glitch on the server. It is of course a bug, since your code will always take some time and use some memory.

    What should we do when the k

    street_rider @ 11 Dec 2010 11:05 AM

    What should we do when the k input is 0.

    This is rubbish, my solution

    chrisparton @ 15 Dec 2010 09:51 AM

    This is rubbish, my solution works fine on my laptop but I get a time limit exceeded error from the judge. I copy+pasted one of the successful submissions that apparently took 0.00 seconds and got the same message. Are the judging computers slower than they were before?

    Perhaps. But if you had read

    triplem @ 15 Dec 2010 10:19 AM

    Perhaps. But if you had read the FAQ like it says to under Post new comment, or any of the comments above yours, you would know that cin and cout are extremely slow and that you should never use them on the online judge.

    (Those earlier submissions should get TLE; that is what this problem is designed for. Not sure why they were accepted).

    To Stephen Merriman, I have

    ksinkar @ 22 Dec 2010 07:33 AM

    To Stephen Merriman,

    I have seen many solutions that have been accepted as successful submissions with cin and cout. Why is it so?

    Either there was a bug in the

    triplem @ 22 Dec 2010 01:57 PM

    Either there was a bug in the judge or things were different a long time ago. Probably the former.

    This is BS i did it using

    pervysage @ 21 Jan 2011 12:14 AM

    This is BS i did it using fread() and still shows TLE.

    Your code runs forever on the

    triplem @ 21 Jan 2011 06:33 AM

    Your code runs forever on the sample input due to your combination of scanf and fread. Read the FAQ if you aren't sure how to test your code.

    OMG....very difficult.i can

    idophotograph @ 7 Feb 2011 05:21 PM

    OMG....very difficult.i can not solved it

    My program runs well with

    jsr_ankit @ 11 Feb 2011 03:26 AM

    My program runs well with getch() on my compiler but here it gives a compile time error. Then if I omit the getch() command it says your program cant execute in DOS mode. To avoid getch() compile error i included conio.h library and again it says invalid library. PLEASE HELP!!

    There's no such thing as

    triplem @ 11 Feb 2011 05:18 AM

    There's no such thing as getch() or conio.h in standard C/C++, and you should never need to use them anyway. I suggest you use a better compiler.

    Can anyone please point out

    antonyajay21 @ 19 Feb 2011 10:29 AM

    Can anyone please point out my error....I'm getting a 'runtime error'

     

    #include "stdio.h"
    void main(void){
    long n=0,k=0,l=0,count=0,i;
    scanf("%ld %ld",&n,&k);   
    for(i=0;i<n;i++){
    scanf("%ld",&l);   
    if(l%k==0)count++;
    }       
    printf("%ld",count);
    }

    Please read the FAQ.

    triplem @ 19 Feb 2011 11:39 AM

    Please read the FAQ.

    k now i get it. It's

    antonyajay21 @ 21 Feb 2011 08:39 AM

    k now i get it. It's mandatory to return a value back. Thanks Stephen

    My code below gives time

    abdulqadir791 @ 24 Feb 2011 01:38 PM

    My code below gives time limit exceeded.. Can someone please help me with this one..

    # include <iostream>

    using namespace std;

    int main()

    {

    int n;

    long k,p,count=0;

    cin>>n;

    cin>>k;

    while(n--)

    {

    cin>>p;

    if(p%k==0)

    ++count;

    }

    cout<<count<<endl;

    return 0;

    }

    Got it.. just have to use

    abdulqadir791 @ 24 Feb 2011 01:48 PM

    Got it.. just have to use printf/scanf instead of cout/cin... :)

    admin can you give me link or

    fluteofcoder @ 1 Mar 2011 11:50 PM

    admin can you give me link or reference which claims print/scanf are faster than cin/cout?

    Wow. I used the exact same

    isaacmj @ 5 Mar 2011 02:20 AM

    Wow. I used the exact same code but changed the input/output lines.

    cin/cout -> Time limit exceeded

    scanf/printf -> accepted, in 5.44 seconds

    That means scanf/printf is at least two and a half seconds faster than cin/cout

    import java.io.*;   class

    ajinkya02 @ 6 Mar 2011 02:59 PM

    import java.io.*;

     

    class Main

    {

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

    {

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

    int n=Integer.parseInt(br.readLine());

    int k=Integer.parseInt(br.readLine());

    int count=0,num;

    for(int i=1;i<=n;i++)

    {

    num=Integer.parseInt(br.readLine());

    if(num%k==0)

    count++;

    }

    System.out.println(count);

    }

    }

     

    Hey whats problem in the above code.It gives me runtime error.

    not sure why this code is

    tihor14 @ 14 Mar 2011 03:43 PM

    not sure why this code is giving TLE

    #include<iostream>

    using namespace std;

    int main(){
    int n,k,x,val=0;
    cin>>n>>k;
    while(n--){
    cin>>x;
    if(x%k==0)
    val++;
    }
    cout<<val<<"n";
    return 0;
    }

    I have read the above post and seen some successful solutions. This is the sixth best

  • #include<iostream>
  • using namespace std;
  • int main()
  • {
  • int t,div,did,count=0;
  • cin>>t>>div;
  • while(t--)
  • {
  • cin>>did;
  • if(did%div==0)
  • count++;
  • }
  • cout<<count<<endl;
  • return 0;
  • }
  • Not sure how it is different from mine. Can anyone be kind enough to explain?

    @rohit   man, read the

    arroganthari @ 19 Mar 2011 01:29 PM

    @rohit

     

    man, read the comments completely regarding cin and cout.

    The answer for that second part of your question is that there must be a bug in the judge which sometimes judges solutions to be AC instead of TLE.

    my code for this problem is

    rumman0786 @ 26 Mar 2011 04:48 PM

    my code for this problem is this---

    import java.io.*;

    public class MAIN{

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

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

    String s=br.readLine();

    String [] x=s.split("");

    int t=Integer.parseInt(x[0]);

    int d=Integer.parseInt(x[0]);

    int ans=0,v;

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

    v=Integer.parseInt(br.readLine());

    ans=(v%d==0) ? (++ans) : ans ;

    }

    System.out.print(ans);

    }

    }

     

     

    It gives runtime error.....can anyone tell me whats wrong wd it?

    use util.Scanner    class to

    kurmianil @ 10 Apr 2011 08:34 AM

    use util.Scanner    class to solve this one.

    My code is this: #include

    savvy @ 20 Apr 2011 12:03 AM

    My code is this:

    #include <iostream>

    using namespace std;
    int main()

    {
    unsigned long int n;
    unsigned long int k;
    unsigned long int num,count=0;

    cin>>n>>k;
    while(n--){
    cin>>num;
    if(num%k==0)
    count++;  
    }
    cout<<count;
    return 0;
    }

    It is giving me time exceeded error....to check whether this error is relevant I checked the submission with one of the accepted solutions guess what It still gave a time exceeded error :O

    my code is giving time limit

    khush @ 22 Apr 2011 06:33 PM

    my code is giving time limit exceeded errore ...can anyone please help to me solve this problem...??

    link to my code is    http://www.codechef.com/viewsolution/529979

    I submitted my solution and

    aman05 @ 30 Apr 2011 10:21 AM

    I submitted my solution and it gave timelimit exceeded. My code is

    #include <iostream>

    using namespace std;

    int main( void )
    {
    long x,k,z,result;
    cin>>x>>k;
    for(;x-->0;)
    {
    cin>>z;         //"line is this"
    if(z%k == 0)
    {++result;}
    }
    cout<<result;
    return 0;
    }

    in the final solution instead of using a variable to store datathey use an array to do so. I can't understand why is that getting faster because of this.

    i need help. my solution is

    shashankpotter @ 11 May 2011 09:19 AM

    i need help. my solution is equivalent to successful submissions but it says time limit exceeded.

    #include<iostream>

    using namespace std;

    int main()

    {

    long long int n,k,x,count=0;

    cin>>n;

    cin>>k;

    for(long long int i=0;i<n;i++)

    {

    cin>>x;

    if(x%k==0)

    {count++;}

     

    }

    cout<<count;

    cin>>count;

    }

     

    #include int main() { long

    arpitaks502 @ 17 May 2011 05:53 PM
    #include int main() { long long int n,k,t,b=0,i; float c; scanf("%lld%lld",&n,&k); for(i=0;i

    please tell me d fault in d

    arpitaks502 @ 17 May 2011 05:54 PM
    please tell me d fault in d above code!! #include int main() { long long int n,k,t,b=0,i; float c; scanf("%lld%lld",&n,&k); for(i=0;i

    after many unsuccessful

    klerigado @ 20 May 2011 08:15 PM
    after many unsuccessful attempt in c++ i tried to submit code of fastest c++ of INTEST from successful list with time 0.0 but in my case showing time limit exceeded

    Yes, same here! successful

    rohi7 @ 21 May 2011 03:55 PM
    Yes, same here! successful submissions showing time limit exceeded for me too!

    SAME HERE!!!!!

    matsun @ 31 May 2011 09:27 PM
    SAME HERE!!!!!

    i dont understand...i am

    anup1912 @ 30 Jun 2011 11:28 AM
    i dont understand...i am using python and it is giving me a runtime error? no idea why it is like that... i have ensured that the n and k are whitespace separated and and also have carefully read the program...what is wrong??HELP!!

    finally get this thing worked

    kevinfrankly @ 4 Jul 2011 10:08 PM
    finally get this thing worked with scanf and printf .

    #include main() {

    suman3majee9 @ 10 Jul 2011 07:59 PM
    #include main() { unsigned long int n , k ,i,t ,count=0; scanf("%lu %lu",&n,&k); for(i=0; i

    #include main() {

    suman3majee9 @ 10 Jul 2011 08:00 PM
    #include main() { unsigned long int n , k ,i,t ,count=0; scanf("%lu %lu",&n,&k); for(i=0; i

    @ admin I am getting write

    krsinghchandan @ 18 Jul 2011 09:14 PM
    @ admin I am getting write answer on my system without any error and warnings then why runtime error is reported again and again ?

    so I know PHP is a scripting

    kjljon @ 23 Jul 2011 03:23 AM
    so I know PHP is a scripting language. I am just what the fastest anyone has made it go using PHP. I did it in 42.65 seconds my first try and got it down to 21.69 seconds.

    when i use cin in my code

    dreskei @ 3 Aug 2011 10:00 PM
    when i use cin in my code time is exceeding bt by using scanf...its taking arnd 5 sec...can someone explain why...?

    what is da limit of n????

    rajrocks1992 @ 19 Aug 2011 04:46 PM
    what is da limit of n????

    import java.io.*; public

    swastika21 @ 29 Aug 2011 12:15 AM
    import java.io.*; public class abc { public static void main(String[] args)throws IOException { BufferedReader k = new BufferedReader(new InputStreamReader(System.in)); int n,k1,i,no,c=0; n=Integer.parseInt(k.readLine()); k1=Integer.parseInt(k.readLine()); if(k1<=10000000) { for(i=0;i

    import java.io.*; class

    swastika21 @ 29 Aug 2011 12:18 AM
    import java.io.*; class abc { public static void main(String[] args)throws IOException { BufferedReader k = new BufferedReader(new InputStreamReader(System.in)); int n,k1,i,no,c=0; n=Integer.parseInt(k.readLine()); k1=Integer.parseInt(k.readLine()); if(k1<=10000000) { for(i=0;i

    import java.io.*; class

    swastika21 @ 29 Aug 2011 12:22 AM
    import java.io.*; class abc { public static void main(String[] args)throws IOException { BufferedReader k = new BufferedReader(new InputStreamReader(System.in)); int n,k1,i,no,c=0; n=Integer.parseInt(k.readLine()); k1=Integer.parseInt(k.readLine()); if(k1<=10000000) { for(i=0;i

    can anybody tell y this

    nittsat @ 15 Sep 2011 04:46 PM
    can anybody tell y this program getting time limit exceeds ? import java.io.*; import java.util.*; class division { public static void main(String args[]) throws IOException { int total,div,input; int count=0,i=0; Scanner s=new Scanner(System.in); total=s.nextInt(); div=s.nextInt(); if(div > 0) { while(i < total) { input=s.nextInt(); if((input%div) == 0) { count++; } i++; } System.out.println(count); } } }

    or the link to the program

    nittsat @ 15 Sep 2011 04:48 PM
    or the link to the program is http://www.codechef.com/viewsolution/661707

    why am i getting runtime

    amanymca24 @ 17 Sep 2011 06:27 PM
    why am i getting runtime error?? #include #include int main() { long n,t,k,ans=0; scanf("%ld",&n); scanf("%ld",&k); while(n--) { scanf("%ld",&t); if(k!=0 && t!=0) { if(t%k==0) ans++; } } printf("%ld",ans); getch(); return(5); }

    is it possible that on my

    widdoh @ 28 Sep 2011 08:56 PM
    is it possible that on my laptop it takes 0.5ms to execute while on your system it takes 660ms? I am using a 100MB file with 10M entries.

    Hi, I tried all i can to beat

    widdoh @ 28 Sep 2011 10:43 PM
    Hi, I tried all i can to beat the time of 140ms taken by many c# programs but the best i could come up with was 660ms until I gave up and copied the top program code (that claims a 140ms run time) and re-submitted it myself to verify the claim. I was surprised to see that it took over 8 seconds to execute!!!!! Kindly can anyone explain why? Tks

    when i use cout and cin its

    loop_break @ 29 Sep 2011 01:53 AM
    when i use cout and cin its giving time out exception.but if i replace them with printf and scanf program is working within time limmit.reason?

    printf and scanf are working

    sude2p @ 30 Sep 2011 09:46 PM
    printf and scanf are working well but execution time is long(5s)..How to reduce the time..?any idea..There must be a way..!

    done in C ...but its takin

    shubham_4mnnit @ 1 Oct 2011 01:50 AM
    done in C ...but its takin 5.66 sec ......any ways to decrease execution time...?????

    my code is giving wrong

    ritik_arora13 @ 5 Oct 2011 04:43 PM
    my code is giving wrong answer but i have checked it for few examples but it is working fine..pls can anyone help with that. link to my code is http://www.codechef.com/viewsolution/687546

    @nitsat: use bufferedreader

    ritik_arora13 @ 5 Oct 2011 04:46 PM
    @nitsat: use bufferedreader instead of scanner to take input it wont show time limit exceeded.

    Hey i did submit ma code

    cephy_vks7 @ 10 Oct 2011 09:29 PM
    Hey i did submit ma code succefully in C :) but it took 5.4 seconds! Could anyone out here tell me general ways to reduce time? Any books, online resources :) I would be glad :) As i am a newbie to programming I have least idea abt time cutting on running of the program. thank you ina advance..

    str=raw_input().split() n,k=

    vijeenroshpw @ 25 Oct 2011 10:45 PM
    str=raw_input().split() n,k= int(str[0]),int(str[1]) j=0 for i in range(0,n): if not input() % k : j=j+1 print j There is some problem with above script .It is havingg an time out exception. please help ..

    #include #include #include

    dispareil @ 4 Nov 2011 05:46 PM
    #include #include #include #define SIZE 65536 int main(int argc, char *argv[]) { char buffer[SIZE]; unsigned long n, k, ti, d; int c, j; d = 0; scanf("%lu %lun", &n, &k); ti = 0; while ( (c=fread(buffer, 1, SIZE, stdin)) > 0) { for (j=0;j

    #include int main() {

    cooper @ 7 Dec 2011 03:46 PM
    #include int main() { unsigned int n,k,t; int i,count=0; scanf("%u%u",&n,&k); for(i=0;i

    hey my execution time is

    deepanshum007 @ 16 Dec 2011 11:29 PM
    hey my execution time is 10.08 sec but is accepted successfully ???help

    //Working and Executed Java

    nikhilsv92 @ 19 Dec 2011 08:31 PM
    //Working and Executed Java code import java.io.BufferedReader; import java.io.InputStreamReader; import java.util.StringTokenizer; public class Main { public static void main(String[] args) throws Exception { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer str=new StringTokenizer(br.readLine()); int n=Integer.parseInt(str.nextToken()); int k=Integer.parseInt(str.nextToken()); int count=0; long temp; for(int i=0;i

    I find it unusual that my

    angelotan @ 14 Jan 2012 08:03 PM
    I find it unusual that my code below only got accepted only after removing the the if statement's brackets: http://www.codechef.com/viewsolution/793540 What am I missing here? Won't the if statement miss the line n--; without those brackets?

    import java.io.*; public

    rajaagopal @ 21 Jan 2012 04:10 PM
    import java.io.*; public class Main { public static void main(String[] args)throws IOException { BufferedReader ds=new BufferedReader(new InputStreamReader(System.in)); int num=Integer.parseInt(ds.readLine()); int div=Integer.parseInt(ds.readLine()); int count=0; if(div!=0) { for(int i=0;i

    Why this code is reported as

    manish.kumar @ 21 Jan 2012 04:12 PM
    Why this code is reported as "Wrong Answer" import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.StringTokenizer; class Input { public static void main(String[] ar) throws IOException{ BufferedReader br = new BufferedReader( new InputStreamReader( System.in ) ); char buff[] = new char[12000]; int i = br.read( buff, 0, 12000 ); int n, k, number; int count = 0; String s = new String(buff); s = s.trim(); StringTokenizer st = new StringTokenizer(s, " "); n = Integer.parseInt( st.nextToken().trim() ); s = st.nextToken(); st = new StringTokenizer( s, "n" ); k = Integer.parseInt( st.nextToken().trim() ); while( st.hasMoreTokens() ) { number = Integer.parseInt(st.nextToken().trim()); if( number % k == 0 ) count++; } System.out.println(count); } }

    Ruby hint: Putting the read

    benfulton @ 4 Feb 2012 08:39 PM
    Ruby hint: Putting the read loop into a yield function will run too slowly.

    SUCCESSFUL SUBMISSIONS FOR THIS PROBLEM:

    Programming Competition Fetching successful submissions
    Directi Go for Gold

    HELP

    Program should read from standard input and write to standard output. After you submit a solution you can see your results by clicking on the [My Submissions] tab on the problem page. Below are the possible results:

     

    • Accepted Your program ran successfully and gave a correct answer. If there is a score for the problem, this will be displayed in parenthesis next to the checkmark.
    • Time Limit Exceeded Your program was compiled successfully, but it didn't stop before time limit. Try optimizing your approach.
    • Wrong Answer Your program compiled and ran succesfully but the output did not match the expected output.
    • Runtime Error Your code compiled and ran but encountered an error. The most common reasons are using too much memory or dividing by zero. For the specific error codes see the help section.
    • Compilation Error Your code was unable to compile. When you see this icon, click on it for more information.
    • If you are still having problems, see a sample solution here.

    CodeChef is a global programming communityCodeChef hosts online programming competitions
    CodeChef is a non-commercial competitive programming community
    • About CodeChef
    • About Directi
    • CEO's Corner
    • C-Programming
    • Programming Languages
    • Contact Us
    © 2009 Directi Group. All Rights Reserved. CodeChef uses SPOJ © by Sphere Research Labs
    In order to report copyright violations of any kind, send in an email to copyright@codechef.com
    CodeChef a product of Directi
    The time now is:
    CodeChef - A Platform for Aspiring Programmers

    CodeChef was created as a platform to help programmers make it big in the world of computer programming. At CodeChef we work hard to revive the geek in you by hosting programming contests on a monthly basis. We also aim to have training sessions and events related to online programming for programmers around the world. Apart from providing a platform for programming competitions, CodeChef also has various tutorials and forum discussions to help those who are new to the world of computer programming.

    Practice Section - A Place to hone your 'Computer Programming Skills'

    Try your hand at one of our many practice problems and submit your solution in a language of your choice. Our judge accepts solutions in over 35+ programming languages. Online programming was never this much fun! Receive points, and move up through the CodeChef ranks. Use our practice section to better prepare yourself for the multiple programming competitions that take place through-out the month on CodeChef.

    Compete - Monthly Programming Contests and Cook-offs

    Here is where you can show off your computer programming skills. Take part in our 10 day long monthly programming contests and the shorter format Cook-off programming contests. Put yourself up for recognition and win great prizes. Prizes worth up to Rs.20,000 and $700 are up for grabs every month along with lots more CodeChef goodies.

    Discuss

    Are you new to computer programming? Do you need help with algorithms? Then be part of CodeChefs Forums and interact with all our programmers love helping out other programmers and share their ideas.

    CodeChef Community

    As part of our Educational initiative, we give institutes the opportunity to associate with CodeChef in the form of Campus Chapters. Hosting online programming competitions is not the only feature on CodeChef. Be a part of the CodeChef community through CodeChef meetups and techtalks. You can also host a programming contest for your institute on CodeChef and be a guest author on our blog.

    Domain Name Registration, Web hosting, and Website Design provided by BigRock.com