Rezultati

Up. imeNalogaJezikRezultatČas oddaje
jam-2018 Zaletavanje Java 100/100OK 19. apr '18 @ 18:35

Test Točke Porabljen spomin Porabljen čas Status
#1 14/14 35,266 MiB 0,033 s OK
#2 14/14 42,465 MiB 0,047 s OK
#3 14/14 42,742 MiB 0,046 s OK
#4 14/14 41,566 MiB 0,090 s OK
#5 14/14 45,660 MiB 0,048 s OK
#6 15/15 43,773 MiB 0,108 s OK
#7 15/15 42,613 MiB 0,089 s OK

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

public class A {

    static class Avto {

        int i;
        int x;
        int y;
        boolean gor;

        int diagonala;

        Avto(int i, Scanner sc) {
            this.i = i;
            sc.nextLine();
            char dir = sc.next().charAt(0);
            gor = dir == 'G';
            x = sc.nextInt();
            y = sc.nextInt();
            diagonala = x + y;
        }

        @Override
        public String toString() {
            return "Avto{" +
                    "i=" + i +
                    ", x=" + x +
                    ", y=" + y +
                    ", gor=" + gor +
                    '}';
        }
    }

    static class Karambol implements Comparable<Karambol> {

        int time;
        int a;
        int b;

        Karambol(int a, int b) {
            this.a = a;
            this.b = b;
            this.time = Math.abs(avti[a].x - avti[b].x);
        }

        @Override
        public int compareTo(Karambol karambol) {
            return time - karambol.time;
        }

        @Override
        public String toString() {
            return "Karambol{" +
                    "time=" + time +
                    ", a=" + avti[a].i +
                    ", b=" + avti[b].i +
                    '}';
        }
    }

    private static int n, w, h;

    private static void swap(int i, int j) {
        avti[i].gor = !avti[i].gor;
        avti[j].gor = !avti[j].gor;

        if(!avti[i].gor) {
            avti[i].y = avti[j].y;
            avti[j].x = avti[i].x;
        } else {
            avti[j].y = avti[i].y;
            avti[i].x = avti[j].x;
        }

        Avto a = avti[i];
        avti[i] = avti[j];
        avti[j] = a;

        // System.out.println("swap: " + avti[i] + ", " + avti[j]);
    }

    static Avto []avti;

    public static void main(String[] args) {

        Scanner scanner = new Scanner(System.in);

        n = scanner.nextInt(); w = scanner.nextInt(); h = scanner.nextInt();

        avti = new Avto[n];

        for (int i = 0; i < n; i++) {
            avti[i] = new Avto(i, scanner);
        }


        Arrays.sort(avti, Comparator.comparingInt(a -> a.diagonala));

        int start = 0, end = 0;

        while(start < n) {

            while(end < n && avti[start].diagonala == avti[end].diagonala) end++;

            //System.out.println("diagonala " + avti[start].diagonala + " from " + start + " to " + end);

            Karambol []karamboli = new Karambol[(end-start) * (end-start - 1) / 2];

            int k = 0;
            for (int i = start; i < end; i++)
                for (int j = i + 1; j < end; j++)
                    if ( avti[i].gor != avti[j].gor) {

                        if((avti[i].gor && avti[i].y < avti[j].y) ||
                                (avti[j].gor && avti[j].y < avti[i].y)) {

                            karamboli[k++] = new Karambol(i, j);
                        }
                    }

            Karambol []karamboli2 = new Karambol[k];
            for(int i = 0; i < k; i++) {
                karamboli2[i] = karamboli[i];
            }

            Arrays.sort(karamboli2);

            for(int i = 0; i < k; i++) {
                swap(karamboli2[i].a, karamboli2[i].b);
            }

            start = end;
        }


        Arrays.sort(avti, Comparator.comparingInt(avto -> avto.i));
        for (int i = 0; i < n; i++) {
            if(avti[i].gor) {
                avti[i].y = h;
            } else  {
                avti[i].x = w;
            }
            System.out.println(avti[i].x + " " + avti[i].y);
        }

    }

}