Rezultati

Up. imeNalogaJezikRezultatČas oddaje
bitikubiti-2017 Jungle Speed Java 100/100OK 11. maj '17 @ 17:17

Test Točke Porabljen spomin Porabljen čas Status
#1 9/9 32,969 MiB 0,000 s OK
#2 9/9 31,047 MiB 0,000 s OK
#3 9/9 31,559 MiB 0,000 s OK
#4 9/9 34,953 MiB 0,000 s OK
#5 9/9 31,316 MiB 0,000 s OK
#6 9/9 33,016 MiB 0,000 s OK
#7 9/9 34,969 MiB 0,000 s OK
#8 9/9 31,094 MiB 0,000 s OK
#9 9/9 34,215 MiB 0,000 s OK
#10 9/9 34,238 MiB 0,000 s OK
#11 10/10 33,465 MiB 0,000 s OK

Ocenjevani program (B.java):
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.LinkedList;
import java.util.Queue;
import java.util.concurrent.ArrayBlockingQueue;

/**
 * Created by bitikubiti-2017 on 5/11/17.
 */
public class B {
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int N = Integer.parseInt(br.readLine());
        String[] split = br.readLine().split(" ");
        LinkedList<Integer>[] roke = new LinkedList[N];
        for (int i = 0; i < N; i++) {
            roke[i] = new LinkedList<Integer>();
        }
        for (int i = 0; i < split.length; i++) {
            int s = Integer.parseInt(split[i]);
            roke[i%N].addFirst(s);
        }
        LinkedList<Integer>[] kupi = new LinkedList[N];
        for (int i = 0; i < N; i++) {
            kupi[i] = new LinkedList<Integer>();
        }
        int trenutni = 0;
        while(true){
            if(roke[trenutni].isEmpty()){
                roke[trenutni] = kupi[trenutni];
                kupi[trenutni] = new LinkedList<>();
            }
            int cur = roke[trenutni].getFirst();
            kupi[trenutni].addLast(cur);
            roke[trenutni].removeFirst();
            for (int i = 0; i < N; i++) {
                if(i == trenutni)continue;
                if(!kupi[i].isEmpty() && kupi[i].getLast() == cur){
                    if(roke[i].isEmpty()){
                        System.out.println((i+1));
                        return;
                    }
                    roke[trenutni].addAll(kupi[i]);
                    roke[trenutni].addAll(kupi[trenutni]);
                    kupi[i] = new LinkedList<>();
                    kupi[trenutni] = new LinkedList<>();
                    trenutni--;
                    break;
                }
            }
            trenutni = (trenutni+1)%N;
        }
    }
}