Rezultati

Up. imeNalogaJezikRezultatČas oddaje
HeapHeapH.array-2018 Niz Java 100/100OK 19. apr '18 @ 19:03

Test Točke Porabljen spomin Porabljen čas Status
#1 10/10 35,980 MiB 0,000 s OK
#2 10/10 34,691 MiB 0,000 s OK
#3 10/10 39,766 MiB 0,000 s OK
#4 10/10 38,230 MiB 0,000 s OK
#5 10/10 39,301 MiB 0,000 s OK
#6 10/10 37,656 MiB 0,000 s OK
#7 10/10 42,035 MiB 0,000 s OK
#8 10/10 39,340 MiB 0,000 s OK
#9 10/10 41,609 MiB 0,000 s OK
#10 10/10 39,609 MiB 0,000 s OK

Ocenjevani program (Niz.java):
import java.util.Random;
import java.util.Scanner;

/**
 * Created by HeapHeapH.array-2018 on 4/19/18.
 */
public class Niz {
    static char[] nizTable;
    static int res = 0;

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int n = Integer.parseInt(sc.nextLine())+4;
        String a ="11" +sc.nextLine()+"11";
        nizTable = a.toCharArray();

        /*Random rand = new Random();
        nizTable = new char[100000];
        for(int i=0;i<100000;i++){
            nizTable[i] = (char) (rand.nextInt(2)+48);
        }*/
        int[] bitsSaved = new int[n];
        for (int i = 2; i < n-2; i++) {

            bitsSaved[i] = findNum(i-2);
            if(bitsSaved[i-2]==1){
                if(bitsSaved[i]==2){
                    bitsSaved[i-2]--;
                    bitsSaved[i-1]--;
                    bitsSaved[i] -= 2;
                    nizTable[i] = '1';
                }
                else {
                    bitsSaved[i-2]--;
                    bitsSaved[i-1]--;
                    bitsSaved[i] --;
                    nizTable[i] = '0';
                }
                res++;
            }
        }
        /*int a = changeBits(n, bitsSaved);
        while(a!=0){
            boolean flag = false;
            for(int i=0;i<n;i++){
                if(bitsSaved[i]==2){
                    if(nizTable[i]=='1'){
                        nizTable[i]='0';
                    }
                    else {
                        nizTable[i]='1';
                    }
                    res++;
                    flag = true;
                }
            }
            a = changeBits(n,bitsSaved);
            if(flag){
                continue;
            }
            for(int i=0;i<n;i++){
                if(bitsSaved[i]==1){
                    if(nizTable[i]=='1'){
                        nizTable[i]='0';
                    }
                    else {
                        nizTable[i]='1';
                    }
                    a = changeBits(n,bitsSaved);
                    res++;
                    flag = true;
                    break;
                }
            }
        }*/
        System.out.println(res);
    }

    public static int changeBits(int n, int[] bitsSaved) {
        int vsota=0;
        for (int i = 0; i < n; i++) {
            if(!(i<2) && !(i>n-3)){
                bitsSaved[i] = findNum(i-2);
                vsota += bitsSaved[i];
            }
        }
        return vsota;
    }

    static int findNum(int v){
        int st = 0;
        for(int i=0;i<3;i++){
            if(nizTable[v+i]=='0' && nizTable[v+i+1]=='1' && nizTable[v+i+2]=='0'){
                st++;
            }
        }
        return st;
    }
}