Rezultati

Up. imeNalogaJezikRezultatČas oddaje
lablizards-2017 Prijateljske besede Java 0/100Napačen odgovor (WA) 20. apr '17 @ 18:15

Test Točke Porabljen spomin Porabljen čas Status
#1 12/12 36,988 MiB 0,000 s OK
#2 0/12 40,754 MiB 0,000 s Napačen odgovor
Tvoj izhod:
​14
<<<EOF>>>
Pravilen izhod:
​76
<<<EOF>>>
#3 0/12 109,680 MiB 2,723 s Napačen odgovor
Tvoj izhod:
​122
<<<EOF>>>
Pravilen izhod:
​2978
<<<EOF>>>
#4 0/12 122,906 MiB 1,893 s Napačen odgovor
Tvoj izhod:
​21
<<<EOF>>>
Pravilen izhod:
​2154
<<<EOF>>>
#5 0/13 116,469 MiB 1,746 s Napačen odgovor
Tvoj izhod:
​14
<<<EOF>>>
Pravilen izhod:
​20
<<<EOF>>>
#6 0/13 120,211 MiB 2,007 s Napačen odgovor
Tvoj izhod:
​17
<<<EOF>>>
Pravilen izhod:
​819
<<<EOF>>>
#7 0/13 116,152 MiB 2,081 s Napačen odgovor
Tvoj izhod:
​5
<<<EOF>>>
Pravilen izhod:
​1
<<<EOF>>>
#8 0/13 110,340 MiB 1,737 s Napačen odgovor
Tvoj izhod:
​17
<<<EOF>>>
Pravilen izhod:
​1178
<<<EOF>>>

Ocenjevani program (FriendlyWords.java):
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

/**
 * Created by Jan Pomer on 20. 04. 2017.
 */

class Word {
    String leftKey;
    String rightKey;
    int leftWing = 0;
    int rightWing = 0;
    List<Word> left = new ArrayList<>();
    List<Word> right = new ArrayList<>();

    public boolean insert(String word, String front, String back) {
        boolean a = false;
        boolean b = false;

        for (Word l : left) {
            boolean tmp = l.insert(word, front, back);

            if (!a && tmp) {
                a = true;
            }

            if (tmp) leftWing++;
        }

        for (Word r : right) {
            boolean tmp = r.insert(word, front, back);


            if (!b && tmp) b = true;

            if (tmp) rightWing++;
        }

        if (!a && front.equals(leftKey)) {
            Word w = new Word();
            w.leftKey = front;
            w.rightKey = back;

            left.add(w);

            leftWing++;

            a = true;
        }

        if (!b && back.equals(rightKey)) {
            Word w = new Word();
            w.leftKey = front;
            w.rightKey = back;

            right.add(w);

            rightWing++;

            b = true;
        }

        return b || a;
    }
}

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

        int N = scanner.nextInt();
        scanner.nextLine();

        String[] words = new String[N];

        for (int n = 0; n < N; n++) {
            words[n] = scanner.nextLine();
        }

        List<Word> trees = new ArrayList<>();
        Word word = new Word();
        word.leftKey = words[0].substring(0, 3);
        word.rightKey = words[0].substring(words[0].length() - 3);

        trees.add(word);

        for (int i = 1; i < words.length; i++) {
            String front = words[i].substring(0, 3);
            String back = words[i].substring(words[i].length() - 3);

            boolean b = false;
            for (Word t : trees) {

                boolean tmp = t.insert(words[i], front, back);

                if(!b && tmp) {
                    b = true;
                }
            }

            if(!b) {
                word = new Word();
                word.leftKey = words[i].substring(0, 3);
                word.rightKey = words[i].substring(words[i].length() - 3);

                trees.add(word);
            }
        }

        int max = 0;

        for(Word w: trees) {
            if(w.leftWing > max) {
                max = w.leftWing;
            }

            if(w.rightWing > max) {
                max = w.rightWing;
            }
        }

        System.out.println(max + 1);
    }
}