Page 5 of 5

Re: 498 TLE

Posted: Sat Feb 14, 2009 7:13 am
by Obaida
Help me I got TLE..

Code: Select all

removed
Ok now i know why i am TLE.. But someone please help me to allocate the eof for this program i don't know how to do it. I got TLE in another problem for this. :oops: :oops: :oops:

Re: 498 TLE

Posted: Sat Feb 14, 2009 6:40 pm
by Moshiur Rahman
I made the following change in your second while loop and got AC:

Code: Select all

while(1)
{
     int ret = scanf("%d%c",&c[i++],&a);
     if(ret != 2) return 0;
     if(a==10)break;
}
good luck!

Re: 498 TLE

Posted: Sun Feb 15, 2009 5:42 am
by Obaida
Thank you 2 much!! Now i can avoid TLE in some oter problems too. :)
And learned a good lesson 2. :D

Re: How to get even number line input???(498,10268)

Posted: Sat Jul 28, 2012 9:18 am
by bill8124
Use fgets(line1, 200, stdin) instead of gets(line1)
gets() don't do any length control and may cause buffer overflow. (e.g. Write other variables and make an error in your program)

498 Why am i getting RTE?

Posted: Thu Mar 28, 2013 4:19 am
by ccmoralesj
Hi, i've been trying this problem and i have tried ALL test cases i've found, but i still getting RTE, maybe it's the way i read the input... i don't know.. if someone please could help me...

Code: Select all

import java.io.*;

public class Main{
	public static void main(String[] Args)throws IOException{
		BufferedReader read= new BufferedReader(new InputStreamReader(System.in));
		String line1,line2;
		String[] coef, exes;
		int x,polly,lengthe,lengthcoef;
		while(((line1=read.readLine())!=null)&&((line2=read.readLine())!=null)){
			line1=line1.trim();
			coef=line1.split("\\s");
			line2=line2.trim();
			exes=line2.split("\\s");
			lengthe= exes.length;
			lengthcoef= coef.length;
			for(int i=0;i<lengthe;i++){
				polly=Integer.parseInt(coef[0]);
				x=Integer.parseInt(exes[i]);
				for(int k=1;k<lengthcoef;k++){
					polly=polly*x + Integer.parseInt(coef[k]);
				}
				System.out.print(polly+" ");
			}
			System.out.println();
		}
		read.close();
		System.exit(0);
	}
}

Re: 498 Why am i getting RTE?

Posted: Thu Mar 28, 2013 9:25 pm
by brianfry713
Don't print a space at the end of a line.

Re: 498 - polly the polynomial

Posted: Sun Aug 11, 2013 9:24 am
by techbd123
Why PE in this code???
Please help me to find out.

Code: Select all

CODE REMOVED AFTER GETTING AC

Re: 498 - polly the polynomial

Posted: Wed Aug 14, 2013 9:58 pm
by brianfry713
Don't print a space at the end of a line.

Re: 498 - polly the polynomial

Posted: Sat Aug 17, 2013 2:57 pm
by techbd123
Thanks to Guru! Brianfry.

Re: 498 - polly the polynomial

Posted: Sat Dec 07, 2013 9:21 am
by sady
Can anyone plz help me, i'm getting TLE. I'm a new comer and this my first submission. Thanks in advance.

Code: Select all

 code removed after getting ac

Re: 498 - polly the polynomial

Posted: Mon Dec 09, 2013 9:40 pm
by brianfry713
Don't print a space or a '\b' at the end of a line.

Re: 498 - polly the polynomial

Posted: Mon Dec 23, 2013 10:13 am
by sady
:P thanks @brianfry713

498 rte

Posted: Thu Mar 27, 2014 4:00 am
by zyt144
Hi I tried so many times but keep getting rte... I have removed the spaces at the end of each line, and did not use Math.pow...
Can anyone help??

Code: Select all

import java.io.*;
import java.util.*;
import java.lang.*;

public class Main {
	public static void main(String args[]) throws IOException {
		BufferedReader cin = new BufferedReader(new FileReader("input.txt"));
		// BufferedReader cin = new BufferedReader(new InputStreamReader(System.in));
		String line1;
		int count =0;
		while ((line1 = cin.readLine()) != null) {
			if(count!=0)
				System.out.println();
			
			String line2 = cin.readLine();
			String[] parts1 = line1.split(" ");
			String[] parts2 = line2.split(" ");
			int cl = parts1.length;
			int xl = parts2.length;
			int[] coeff = new int[cl];
			for (int i = 0; i < cl; i++) {
				coeff[i] = Integer.parseInt(parts1[i]);
			}
			int[] indep = new int[xl];
			for (int i = 0; i < xl; i++) {
				indep[i] = Integer.parseInt(parts2[i]);
			}

			for (int i = 0; i < xl; i++) {
				int x = indep[i];
				int result = 0;
				for (int j = 0; j < cl; j++) {
					int temp=1;
					for(int k=0;k<cl-1-j;k++)
						temp = temp*x;
					result = result + coeff[j]*temp;
				}
				if (i == xl-1)
					System.out.print(result);
				else
					System.out.print(result + " ");
			}
			count++;
		}
		cin.close();
	}

}

Re: 498 rte

Posted: Thu Mar 27, 2014 9:20 pm
by brianfry713
Don't read from a file.