I think it is not a good attitude to ask for extending the time limit.
As you say, there are more than 60 people got accepted within 10s. That means there is some methods to do it in reasonable time.
I think most of us come to this online judge because we want to learn by solving problems. If you don't get fast enough, just think about how to do it faster
P.S. I got it accepted with 8s
My signature:
Please make discussion about the algorithm BRFORE posting source code.
We can learn much more in discussion than reading source code.
From other side:
why problemsetter set time-limit to 40 sec ? I think, that she/he thought that it is reasonable time for solving this problem. So I think, that if problemsetter doesn't set TIME-LIMIT, we should use 10 sec limit. But If PROBLEMSETTER SET LIMIT, we should use your limit .... (and then time-limit could be i.e. 2 sec for other problems ... ). It's my private opinion and I think that when I solve problem in 1/3 of time limit it's good time. I know, that every problem we can solve in very small amount of time, but in many cases it unnecessary ... (this is only my opinion! ) ...
DM
PS. I got Acc in 14 sec
If you really want to get Accepted, try to think about possible, and after that - about impossible ... and you'll get, what you want ....
Born from ashes - restarting counter of problems (800+ solved problems)
If there are 60 who solved this problem in less than 10 seconds then it means it is possible to solve it:). If you are a good programmer then you will try to do it. Every problem that I have met in online contests the TL for easy problems is 10 seconds or more and memory is 16MB or more. It means that a good programmer will solve it in less time and with less memory. The others will use much more memory or full search algorithm and solve it in more than 10 seconds. If you think that you program is correct then try to optimize it with maximum possible ways.
I have a question about the problem specification:
For each line of input produce one line of output. This line should be of one of the following types:
n is not the sum of two primes!
n is the sum of p1 and p2.
For the second case, always make sure that (p2-p1) is positive and minimized.
how can we from there or other parts of the problem to deduce that for 4, or 6 we should output that they are not the sum of 2 primes?
we cannot do 4= 2+2 because 2-2 is not positive, but 4 is not the sum of two primes is also incorrect....and where does it say if it is not case 2 then output case 1?
Why my code gets on high numbers OutOfMemoryError
for example on max N=100000000
100000000
Exception in thread "main" java.lang.OutOfMemoryError
My Code:
import java.io.*;
import java.util.*;
public class GoldbachAndEuler2{
final static long maxI=Integer.parseInt("100000000");
static long stevilo;
public static void main(String[] args){
BufferedReader vhod = new BufferedReader(new InputStreamReader(System.in));
while(true) {
try{
String nn = vhod.readLine().trim();
if (nn.equals("")) break;
int mm = Integer.parseInt(nn);
if(mm - stevilo > 0){
stevilo=mm;
if ((0 < mm) && (mm <= maxI)) {
problemL(mm);
}
else {
System.out.println("Stevilo "+ mm +" ni iz intervala [1, "+maxI+"].");
}
}
else{
System.out.println(stevilo +" - "+mm+" < 0 zato koncamo!" );
break;
}
}
catch(Exception ex){
}
}
}
public static void problemL(int stevilo)
{
boolean[] jePrastevilo = new boolean[stevilo];
for(int i = 2; i < stevilo; i++){jePrastevilo = true;}
for(int i = 2; i * i < stevilo; i++){
if(jePrastevilo){
for(int j = i; i * j < stevilo; j++){jePrastevilo[i*j] = false;}
}
}
int prastevilo = 0;
for (int i = 2; i < stevilo; i++){
if (jePrastevilo) prastevilo++;
}
int seznam[] = new int[prastevilo];
int k = 0;//pomik po seznamu
for(int i = 0; i < stevilo; i++){
if(jePrastevilo){seznam[k++] = i;}
}
int levo = 0, desno = prastevilo-1;
boolean nasliSum=false;
while(levo <= desno) {
if(seznam[levo] + seznam[desno] == stevilo){nasliSum=true; break;}
else if(seznam[levo] + seznam[desno] < stevilo){levo++;}
else{desno--;}
}
if (nasliSum){
System.out.println(stevilo + " is the sum of " + seznam[levo] + " and " + seznam[desno]);
}
else{
System.out.println(stevilo + " is not the sum of two primes!");
}
}
}//class
The judge should have sent you a mail identifying the lines it can't compile.
I just hope it wasnt as silly a mistake as clicking on C instead of C++ if you are using the web based submission tool
Regards,
Suman.
PS: a quick glance on VC.6 shows link errors, it might be due to the fact that you are using both iostream & cstdio, can you explain why you need both of them?
On a mac g++ cribs on void main, and on correcting that, the bool array seems to be too large, again cribs ... reduced it by a factor of 10 and then it compiles happily even with both the headers.So you have your hands full!
Here are the compiler error messages:
03230701_24.c:39: unterminated string or character constant
03230701_24.c:39: possible real start of unterminated constant
You must have compiled your code before sending. The possible cause can be that the email sender program has imposed a line break in your program which has caused a compile error;
The array you hav declared is too big for the judge. You will have to implement the seive using bit. Often we have the misconception that a boolean variable will always occupy 1 bit of memory space as it has two possible values. But the judge should have replied memory limit exceeded but instead it replied compile error.