Rezultati

Up. imeNalogaJezikRezultatČas oddaje
lml-2018 Prehitevanje Java 0/100Prekoračen čas (TLE) 04. okt '18 @ 17:50

Test Točke Porabljen spomin Porabljen čas Status
#1 16/16 40,020 MiB 0,000 s OK
#2 16/16 47,234 MiB 0,000 s OK
#3 17/17 40,117 MiB 0,000 s OK
#4 0/17 99,777 MiB 4,250 s Prekoračen čas
#5 0/17 159,313 MiB 6,720 s Prekoračen čas
#6 17/17 36,902 MiB 0,000 s OK

Ocenjevani program (Pre.java):
import java.util.*;

public class Pre
{
    public static void main(String[]args)
    {
        Scanner skan = new Scanner(System.in);
        Hashtable<String,Integer> table = new Hashtable<String,Integer>();
        String bla = skan.nextLine();
        int n = Integer.parseInt(bla);
        String[] words = new String[n];
        Vector<Integer> vec = new Vector<Integer>();

        for(int i = 0; i < n; i++)
        {
            words[i] = skan.nextLine();
            table.put(words[i],i);
            vec.add(i);
        }

        bla = skan.nextLine();
        int p = Integer.parseInt(bla);
        String x;
        String y;
        int indexx = 0;
        int indexy = 0;

        for(int i = 0; i < p; i++)
        {
            bla = skan.nextLine();
            String[] blabla = bla.split(" ");
            x = blabla[0];
            y = blabla[1];

            for(int j = 0; j < n; j++)
            {
                if(table.get(x) == vec.get(j))
                {
                    indexx = j;
                    break;
                }
            }

            for(int j = 0; j < n; j++)
            {
                if(table.get(y) == vec.get(j))
                {
                    indexy = j;
                    break;
                }
            }

            vec.insertElementAt(table.get(x),indexy);

            if(indexx > indexy)
                vec.remove(indexx + 1);
            else
                vec.remove(indexx);
        }

        for(int i = 0; i < n; i++)
        {
            System.out.println(words[vec.get(i)]);
        }
    }
}