59557RC wrote:i don't understand why RTE i used array size larger than 1000000 :
- - - - -
char ch[1000010];
long int i,j[1000010],k[1000010],n,carry,m;
- - - - -
Your code outputs "Segmentation fault" on my local machine.
I think that it secures the memory too much.
Try to decrease the amount of use of the memory.
static final String ReadLn (int maxLg) // utility function to read from stdin
{
byte lin[] = new byte [maxLg];
int lg = 0, car = -1;
try
{
while (lg < maxLg)
{
car = System.in.read();
if ((car < 0) || (car == '\n')) break;
lin [lg++] += car;
}
}
catch (IOException e)
{
return (null);
}
if ((car < 0) && (lg == 0)) return (null); // eof
return (new String (lin, 0, lg));
}
static final String ReadText (int maxLg) // utility function to read from stdin
{
byte lin[] = new byte [maxLg];
int lg = 0, car = -1;
try
{
while (System.in.available()>0)
{
car = System.in.read();
if ((car < 0)) break;
lin [lg++] += car;
}
}
catch (IOException e)
{
return (null);
}
if ((car < 0) && (lg == 0)) return (null); // eof
return (new String (lin, 0, lg));
}
something like
String input;
int numberOfSums;
String linha ;
linha = ReadLn(50);
numberOfSums=Integer.parseInt(linha.trim());
input = Main.ReadText(5000000);
StringTokenizer linhas= new StringTokenizer(input,"\n");
I have tried all the test cases on this forum for 10013, but I still keep getting WA. Does anyone have any suggestions on as to how I could fix this code?
[code]
#include <stdio.h>
int num1[1000001], num2[1000001];
int result[1000001];
void addNumbers()
{
for(int i = 0; i < 1000001; i++)
{
result[i] = -1;
}
int value = 0;
int carry = 0;
for(int i = 1000000; i >= 0; i--)
{
if(num1[i] == -1 && num2[i] != -1)
{
value = num2[i] + carry;
}
else if(num1[i] != -1 && num2[i] == -1)
{
value = num1[i] + carry;
}
else if(num1[i] != -1 && num2[i] != -1)
{
value = num1[i] + num2[i] + carry;
}
else
{
if(carry == 1)
{
result[i] = 1;
}
I am just wondering if the top solutions to Problem (130013) are clean solutions (that is, every valid Judge (that is a Judge that only refuses wrong answers) would accept them) or if it are "hacks" that try to trick the official Judge - i.e. because they know something about the testcases and take advantage of it?
more precisely: would their code score well with other test cases as well?