Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
Java - why TLE ? please helpimport java.io.*; import java.util.*; class Main { public static void main(String[] args)throws IOException { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); //BufferedReader br=new BufferedReader(new FileReader("in.txt")); StringBuffer s= new StringBuffer(); String linea; StringTokenizer st; int L,T,O,A,B,C,i,j,count; int[]board; boolean statecolors[]; while((linea=br.readLine())!=null) { st=new StringTokenizer(linea); L=new Integer(st.nextToken()); T=new Integer(st.nextToken()); O=new Integer(st.nextToken()); board=new int[L+1]; for(i=1;i<=O;i++) { st=new StringTokenizer(br.readLine()); switch(st.countTokens()) { case 4: st.nextToken(); A=new Integer(st.nextToken()); B=new Integer(st.nextToken()); C=new Integer(st.nextToken()); Arrays.fill(board,Math.min(A,B),Math.max(A,B)+1,C-1); break; case 3: st.nextToken(); A=new Integer(st.nextToken()); B=new Integer(st.nextToken()); statecolors=new boolean[T+1]; count=0; for(j=Math.min(A,B);j<=Math.max(A,B);j++) if(!statecolors[board[j]]){ statecolors[board[j]]=true; count++; } s.append(count+"\n"); break; } } } System.out.println(s); } } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator