Enormous Input TestProblem code: INTEST |
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 |
Comments
SUCCESSFUL SUBMISSIONS FOR THIS PROBLEM:
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.

Fetching successful submissions

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 :)
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
for(int i=0;i
Why is my comment getting truncated?
@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.
Hehe, I did it too. I mean the (less than) sign. Being mistaken for html/xml tags
@Siddharth Saha: the problem has been solved, now u can post ur code without it getting truncated.
y i am getting time limit excedded?
@prasanna: that's the difference between scanf/printf and cin/cout.
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?
i did at once ;)
can we not look at other people's solutions to this problem?
@siddharth This is under consideration.
Would love to see the optimized solutions to this problem.
solutions for this problem are now public...
my program works fine on vs 2005, but here it is giving compilation err...any ideas?
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.
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( )
LoL. I made it first try with 7.92 seconds. (8 second time limit.)
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?
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.
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?
10^7 > 1000000
if i size my array to 10^7 the program crashes, is there another way to size it besides just typing in 10000000
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.
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?
http://www.codechef.com/viewsolution/18435/ ..... successfully submitted code is same as mine .... it shows time exceeds ... any suggestions?
http://www.codechef.com/viewsolution/72328/ ... this is correct link ... sorry for the mistake.
@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
cin and cout are very slow,
cin and cout are on an
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
If the submission page shows
If the submission page shows an error, then your solution is not successful.
#include int main(void) {
http://codepad.org/UFm6O4s1
Don't use cin and cout. Read
Don't use cin and cout. Read the comments above for more information.
Hi I am new to this.Please
Hi I am new to this.Please help me as to where to post the code and the language preference
For language preference, you
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
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
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
is the source limit in problems denote memory limit in MB
It is in bytes.
It is in bytes.
I'm a bit confused -- I
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
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
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
That is what the FAQ is for ;)
Perfect, thanks!
Perfect, thanks!
can you plz explain as to
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
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
scanf() and printf() work here. Take a look at http://www.codechef.com/viewsolution/112280
plz chk my
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
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
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++
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
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()
You could try read()
tarzan solve problem with
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
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
well can any1 plz resolve my queries!!!!!!!!
Reading all input at once and
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
#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
#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
cin / cout are far too slow to solve this problem.
Man..., y this is
Man..., y this is so...........?
can i get the proper reason.........?
plz...............
What do you mean? That is the
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
#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
@Stephen Merriman
thanks man....i got..it...bt..help..me...with..the..previous..comment
I keep getting the status
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
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
Because your while loop will never end?
The fastest C solution
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
@Aniruddha...
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
$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
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
Read the rest of the comments.
Am I not using the
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
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
Hi,
Shouldn't k strictly greater than 0. i.e. (k>0)&&(k<=10000000)
a = int(raw_input('enter the
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
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
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
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
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
Can anyone tell me that will i get the input from keyboard or from a text file?
Did you read the comment
Did you read the comment directly above yours?
can someone please tell me
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
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
@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
*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.
Please do not post code here. Read the FAQ.
@ bob just try scanf in place
@ 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#
Anyone has an idea why C# turns out to be the fastest here ?
I don't get it how seemingly
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
man how are ANY of those numbers divisible by 10 million? O_O
seriously wtf? Do you guys
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
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
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
im gettin a nzec runtime error in my program....wat shud i do???
can any one help me
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
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....
help me dude....
The problem statement tells
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
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
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
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
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
i dont know why wrong ans
please help me
pleasessssssssssssssss
Full Nulled Script English &
Full Nulled Script English & Arabic Scripts
#include<stdio.h> int
#include<stdio.h>
int main()
{
unsigned long int times, num,div, count=0;
scanf("%lu %lu",×, &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
FAQ
How can I check the running
How can I check the running time of a program in Ubuntu linux? There must be some simple way?
Never mind.. I found out.
Never mind.. I found out. It's the 'time' command .
When I browse 'successful
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
FAQ
Can someone give me reason
Can someone give me reason why my code is giving time exceed exception.
http://www.codechef.com/viewsolution/310170
This problem is designed to
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
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
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
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
The definition of runtime error is returning anything but 0 from your main method.
It says that there's NZEC
It says that there's NZEC error..
But theres no stack overflow in my code.
pls help!
pls check this solution this
pls check this solution this gave compilation error ....
http://www.codechef.com/viewsolution/315083
its working fine
plz help me out.. how to
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
its takes 8 time even if i written same code as it shown here 0.14 ?
plz xplain me the quetion in
plz xplain me the quetion in simple language.
My solution was
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
FAQ
I just resubmitted the first
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
@ashish what's exactly is the error can u just let me know????
@amir u did it using colock
@amir u did it using colock tick or so???
error occured in the internal
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
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
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
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
You seem to have been accepted..
whenever im trying to submit
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
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
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
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
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
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
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
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
@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
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) {
I am sorry if Comparing of Code is not allowed. Please inform me if it is.
#include <iostream> using
#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.
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
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
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
@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
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
What should we do when the k input is 0.
This is rubbish, my solution
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
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
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
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
This is BS i did it using fread() and still shows TLE.
Your code runs forever on the
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
OMG....very difficult.i can not solved it
My program runs well with
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
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
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.
Please read the FAQ.
k now i get it. It's
k now i get it. It's mandatory to return a value back. Thanks Stephen
My code below gives time
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
Got it.. just have to use printf/scanf instead of cout/cin... :)
admin can you give me link or
admin can you give me link or reference which claims print/scanf are faster than cin/cout?
Wow. I used the exact same
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
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
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
Not sure how it is different from mine. Can anyone be kind enough to explain?
@rohit man, read the
@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
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
use util.Scanner class to solve this one.
My code is this: #include
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
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
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
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
please tell me d fault in d
after many unsuccessful
Yes, same here! successful
SAME HERE!!!!!
i dont understand...i am
finally get this thing worked
#include main() {
#include main() {
@ admin I am getting write
so I know PHP is a scripting
when i use cin in my code
what is da limit of n????
import java.io.*; public
import java.io.*; class
import java.io.*; class
can anybody tell y this
or the link to the program
why am i getting runtime
is it possible that on my
Hi, I tried all i can to beat
when i use cout and cin its
printf and scanf are working
done in C ...but its takin
my code is giving wrong
@nitsat: use bufferedreader
Hey i did submit ma code
str=raw_input().split() n,k=
#include #include #include
#include int main() {
hey my execution time is
//Working and Executed Java
I find it unusual that my
import java.io.*; public
Why this code is reported as
Ruby hint: Putting the read