getting TLE ...pls suggest me what to do...

i already tried bufferedreader instead of scanner,but still getting the TLE …pls suggest me something…i’m new here…
here is the link :http://www.codechef.com/viewsolution/3145473

solution:

import java.io.*;
 
public class Main
{
static int t,n,t1[][];
int m,k,indx,i,s1,s2,g,b,arr[][],c[],row;
static BufferedReader br = null;
int getrow(int n){
int ro=1;
for (int i = 0; i <n; i++)
{
ro=ro*m;
}
return ro;
}
void data()throws IOException{
try{	
InputStreamReader inp = new InputStreamReader(System.in);
br = new BufferedReader(inp);
n=Integer.parseInt(br.readLine());
t1=new int[t][n];
c=new int[n-1];
m=Integer.parseInt(br.readLine());
k=Integer.parseInt(br.readLine());
row=getrow(n);
System.out.println();
for (int i = 0; i <c.length; i++)
{
c[i]=Integer.parseInt(br.readLine());
if(c[i]!=0 & c[i]!=1){
System.out.println("enter valid values :( ");
return;
}
}
calc();
}catch(Exception b){
System.out.println("enter valid inputs");
data();
}
}
void calc(){
int n1=n,k1=1,counter=0;
arr=new int[row][n];
for (int i = 0; i <n; i++)
{
for (int j = 0; j <row; j++)
{
if(counter==(getrow(n1-1))){
k1++;
if(k1>m){k1=1; }
counter=0;
}
counter++;
arr[j][i]=k1;
}
n1--;k1=1;counter=0;
}
poo();
}
void poo(){
for (i = 0; i <row; i++)
{
indx=0;g=0;
part2();
}	
}
void part2(){
for (int p = 0; p <2; p++)
{
for (int j = 0; j <n; j++)
{
if(arr[i][indx]==arr[i][j]){
s1++;
}
}
s2=s1-s2;s1=0;indx++;
}
if(!condition()){
return;
}
else{
g++;
part2();
}
}
boolean condition(){
if(c[g]==0){
if(s2==0){
s2=0;
return false;
}
else{
s2=0;
if(indx==n){
b++;
if(b==k){
arraysh(i);
i=(int)Math.pow(m,n);
}
return false;}
indx--;
}
}
if(c[g]==1){
if(s2==0)
{
if(indx==n){
b++;
if(b==k){
arraysh(i);
i=(int)Math.pow(m,n);
}
return false;}
indx--;
s2=0;
}
else{
s2=0;
return false;
}
}
return true;
}
void arraysh(int i){
for (int j1 = 0; j1 <t; j1++)
{
for (int j = 0; j <n; j++)
{
t1[j1][j]=arr[i][j];
}
}
}
void result(){
for (int i = 0; i <t; i++)
{
for (int j = 0; j <n; j++)
{
if(t1[i][j]==0){
System.out.println(-1);
break;
}
System.out.print(" "+t1[i][j]);
}
System.out.println();
}
}
void reset(){
indx=0;i=0;s1=0;s2=0;g=0;b=0;row=1;
}
static void inputt()throws IOException{
try{
InputStreamReader inp = new InputStreamReader(System.in);
br = new BufferedReader(inp);
System.out.println("enter number of test cases : ");
t=Integer.parseInt(br.readLine());
 
if(t<0){
System.out.println("enter valid input");
inputt();
}
}catch(Exception e){
System.out.println("enter valid input");
inputt();
}
}
public static void main(String args[])throws IOException{
try{
Main nm=new Main();
Main.inputt();
for (int i2 = 0; i2 <t; i2++)
{
nm.data();
for (int j = 0; j <n; j++)
{
if(t1[i2][j]==0){
System.out.println(-1);
break;
}
System.out.print(" "+t1[i2][j]);
}
System.out.println();
nm.reset();
}
}catch(Exception e){
System.out.println("enter valid inputs");
inputt();
}
}
}

TLE means you are using more time than alloted
you need to reduce the complexity of your program to get your solution accepted
Scanner or Buffer class has minimun role to play here.
Think of a more efficient algorithm :slight_smile:

okk…thanx :slight_smile:

//