Rezultati

Up. imeNalogaJezikRezultatČas oddaje
mrjncoin-2018 Niz Java 100/100OK 19. apr '18 @ 17:39

Test Točke Porabljen spomin Porabljen čas Status
#1 10/10 34,855 MiB 0,000 s OK
#2 10/10 29,406 MiB 0,000 s OK
#3 10/10 42,238 MiB 0,000 s OK
#4 10/10 36,262 MiB 0,000 s OK
#5 10/10 38,270 MiB 0,000 s OK
#6 10/10 39,855 MiB 0,000 s OK
#7 10/10 42,504 MiB 0,000 s OK
#8 10/10 41,238 MiB 0,000 s OK
#9 10/10 37,957 MiB 0,000 s OK
#10 10/10 40,730 MiB 0,000 s OK

Ocenjevani program (Neki.java):
import java.util.Arrays;
import java.util.Scanner;

public class Neki {
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int dolzina = Integer.parseInt(sc.nextLine());
		String niz = sc.nextLine();
		sc.close();
		

		//ce je arr manjsi od 2 ne dej rek
		
		best = 0;
		boolean[] tab = toArr(niz);
		for (int i = 0; i < tab.length-2; i++) {
			if (!tab[i] && tab[i+1] && !tab[i+2]) {
				tab[i+2]=true;
				best++;
			}
		}
		//rek(toArr(niz),0,0);
		System.out.println(best);
	}
	
	public static boolean[] toArr(String niz) {
		boolean tab[] = new boolean[niz.length()];
		
		for (int i = 0; i < tab.length; i++) {
			if(niz.charAt(i)=='0') {
				tab[i]=false;
			}else {
				tab[i]=true;
			}
		}
		return tab;
	}
	
	public static int best = Integer.MAX_VALUE;
	
	public static void rek(boolean tab[], int trenutno, int pos) {
		
		
		if(trenutno>=best) {
			return;
		}
		
		if(pos==tab.length-1) {
			best=trenutno;
			//System.out.println(Arrays.toString(tab)+" "+trenutno+ " "+pos);
			return;
		}
		
		for (int i = pos; i < tab.length-2; i++) {
			if (!tab[i] && tab[i+1] && !tab[i+2]) {

				tab[i+1]=false;
				rek(tab,trenutno+1,i+2);
				tab[i+1]=true;
				
				tab[i+2]=true;
				rek(tab,trenutno+1,i+3);
				tab[i+2]=false;
				break;
			}
		}
	}
}