Rezultati

Up. imeNalogaJezikRezultatČas oddaje
scoreoutofboundsexception-2019 Gozdovi Java 100/100OK 24. apr '19 @ 16:41

Test Točke Porabljen spomin Porabljen čas Status
#1 [več] 10/10 35,371 MiB 0,000 s OK
#2 [več] 10/10 63,188 MiB 0,038 s OK
#3 [več] 10/10 93,043 MiB 0,909 s OK
#4 [več] 10/10 55,719 MiB 0,014 s OK
#5 [več] 10/10 128,199 MiB 3,522 s OK
#6 [več] 10/10 60,355 MiB 0,279 s OK
#7 [več] 10/10 63,672 MiB 0,160 s OK
#8 [več] 10/10 54,641 MiB 0,040 s OK
#9 [več] 10/10 60,590 MiB 0,095 s OK
#10 [več] 10/10 59,250 MiB 0,034 s OK

Ocenjevani program (pice.java):
import java.io.*;
import java.util.*;
class tocka{
	int a,b;
	tocka(int c,int d){
		a=c;
		b=d;
	}
}
public class pice {

	public static void main(String[] args) throws Exception{
		BufferedReader in=new BufferedReader(new InputStreamReader(System.in));
		PrintWriter out=new PrintWriter(System.out);
		while(true) {
			StringTokenizer st=new StringTokenizer(in.readLine());
			int h=Integer.parseInt(st.nextToken());
			int w=Integer.parseInt(st.nextToken());
			if(w==0&&h==0) {
				out.close();
				return;
			}
			char[][]fill=new char[h][w];
			for(int i=0;i<h;i++) {
				String s=in.readLine();
				for(int j=0;j<w;j++) {
					fill[i][j]=s.charAt(j);
				}
			}
			boolean[][]done=new boolean[h][w];
			int count=0;
			int[]dx= {-1,-1,-1,0,0,1,1,1};
			int[]dy= {-1,0,1,-1,1,-1,0,1};
			for(int i=0;i<h;i++) {
				for(int j=0;j<w;j++) {
					if(!done[i][j]) {
						count++;
						Queue<tocka> bfs=new LinkedList<tocka>();
						bfs.add(new tocka(i,j));
						done[i][j]=true;
						while(!bfs.isEmpty()) {
							tocka t=bfs.poll();
							for(int move=0;move<8;move++) {
								try {
									int a=t.a+dx[move];
									int b=t.b+dy[move];
									if(!done[a][b]&&fill[t.a][t.b]==fill[a][b]) {
										done[a][b]=true;
										bfs.add(new tocka(a,b));
									}
								}catch(Exception e) {
									
								}
							}
						}
						
					}
				}
			}
			out.println(count);
		}
	}

}