Rezultati

Up. imeNalogaJezikRezultatČas oddaje
bitikubiti-2017 Pasavci Java 100/100OK 11. maj '17 @ 18:48

Test Točke Porabljen spomin Porabljen čas Status
#1 5/5 26,109 MiB 0,000 s OK
#2 5/5 34,063 MiB 0,000 s OK
#3 5/5 37,859 MiB 0,000 s OK
#4 5/5 40,695 MiB 0,000 s OK
#5 5/5 38,574 MiB 0,000 s OK
#6 5/5 41,324 MiB 0,000 s OK
#7 5/5 37,988 MiB 0,000 s OK
#8 5/5 33,520 MiB 0,000 s OK
#9 6/6 38,098 MiB 0,000 s OK
#10 6/6 60,559 MiB 0,066 s OK
#11 6/6 27,844 MiB 0,000 s OK
#12 6/6 34,820 MiB 0,000 s OK
#13 6/6 25,773 MiB 0,000 s OK
#14 6/6 29,508 MiB 0,000 s OK
#15 6/6 31,219 MiB 0,000 s OK
#16 6/6 33,676 MiB 0,000 s OK
#17 6/6 35,121 MiB 0,000 s OK
#18 6/6 65,059 MiB 0,020 s OK

Ocenjevani program (C.java):
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.HashMap;

/**
 * Created by bitikubiti-2017 on 5/11/17.
 */
public class C {
    static HashMap<String, Integer> map = new HashMap<>();
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String iskan = br.readLine();
        String prvi = br.readLine();
        String drugi = br.readLine();
        int M = Integer.parseInt(br.readLine());
        String[] lasti = new String[M+2];
        String[] firsti = new String[M+2];
        long[] popadi = new long[M+2];
        int l = iskan.length();
        long max = 0;
        firsti[0] = first(prvi, l);
        firsti[1] = first(drugi, l);
        lasti[0] = last(prvi, l);
        lasti[1] = last(drugi, l);

        popadi[0] = popadljivost(prvi, iskan);
        popadi[1] = popadljivost(drugi, iskan);
        max = Math.max(popadi[0], popadi[1]);
        for (int i = 2; i < M+2; i++) {
            String[] split = br.readLine().split(" ");
            int a = Integer.parseInt(split[0]);
            int b = Integer.parseInt(split[1]);
            String aa = lasti[a-1];
            String bb = firsti[b-1];
            popadi[i] = (popadljivost(aa+bb, iskan) + popadi[a-1] + popadi[b-1])%1000000007;
            lasti[i] = last(lasti[a-1]+lasti[b-1], l);
            firsti[i] = first(firsti[a-1]+firsti[b-1], l);
        }
        System.out.println(popadi[M+1]);
    }

    static int popadljivost(String gen, String iskan){
        if(map.containsKey(gen))return map.get(gen);
        int l = iskan.length();
        int result = 0;
        for (int i = 0; i < gen.length() - l + 1; i++) {
            boolean check = true;
            for (int j = 0; j < l; j++) {
                if(gen.charAt(i+j) != iskan.charAt(j)){
                    check = false;
                    break;
                }
            }
            if(check)result++;
        }
        map.put(gen, result);
        return result;
    }

    static String last(String str, int l){
        if(str.length()<l)return str;
        return str.substring(str.length() - l +1);
    }

    static String first(String str, int l){
        if(str.length()<l)return str;
        return str.substring(0, l-1);
    }
}