Rezultati

Up. imeNalogaJezikRezultatČas oddaje
mmj-2017 Pasavci C++ 100/100OK 11. maj '17 @ 20:18

Test Točke Porabljen spomin Porabljen čas Status
#1 5/5 3,137 MiB 0,004 s OK
#2 5/5 3,141 MiB 0,004 s OK
#3 5/5 3,152 MiB 0,004 s OK
#4 5/5 3,160 MiB 0,004 s OK
#5 5/5 3,156 MiB 0,004 s OK
#6 5/5 3,199 MiB 0,004 s OK
#7 5/5 3,199 MiB 0,004 s OK
#8 5/5 3,223 MiB 0,004 s OK
#9 6/6 3,195 MiB 0,004 s OK
#10 6/6 5,141 MiB 0,332 s OK
#11 6/6 3,148 MiB 0,004 s OK
#12 6/6 3,125 MiB 0,004 s OK
#13 6/6 3,145 MiB 0,004 s OK
#14 6/6 3,152 MiB 0,004 s OK
#15 6/6 3,129 MiB 0,004 s OK
#16 6/6 3,129 MiB 0,004 s OK
#17 6/6 3,125 MiB 0,004 s OK
#18 6/6 5,137 MiB 0,338 s OK

Ocenjevani program (main.cpp):
#include <iostream>
#include <string>

using namespace std;
string p;

struct pas{
    string s,e;
    int ag;
    int l;
};

int agr(string s){
    int rez = 0;
    int a = 0;
    while (s.find(p,a) != string::npos){
        a = s.find(p,a)+1;
        rez++;
    }
    return rez;
}

pas bred(pas a,pas b){
    pas c;
    c.ag = (a.ag+b.ag + agr(a.e+b.s)) % 1000000007;
    if (((p.length()-1) == b.e.length()) && ((p.length()-1) == a.s.length())){
        c.e = b.e;
        c.s = a.s;
    }
    else {
        string s = a.e+b.e;
        c.e = "";
        c.s = "";
        for (int i = 0; i < min(p.length()-1,s.length());i++){
            c.s += s[i];
            c.e = s[s.length()-1-i] + c.e;
        }
    }
    return c;
}

int main()
{
    string s,s2;
    int a,b,c,d,e;
    cin >> p >> s >> s2 >> a;
    pas ps[a+2];
    ps[0].ag =agr(s);
    ps[0].s = "";
    ps[0].l = s.length();
    for (int i = 0; i < min(p.length()-1,s.length()); i++) ps[0].s += s[i];
     ps[0].e = "";
    for (int i = 0; i < min(p.length()-1,s.length()); i++) ps[0].e = s[s.length()-1-i] + ps[0].e;
    ps[1].ag =agr(s2);
     ps[1].s = "";
    ps[1].l = s2.length();
    for (int i = 0; i < min(p.length()-1,s2.length()); i++) ps[1].s += s2[i];
     ps[1].e = "";
    for (int i = 0; i < min(p.length()-1,s2.length()); i++) ps[1].e = s2[s2.length()-1-i] + ps[1].e;
    for (int i = 2; i < a+2; i++){
        cin >> b >> c;
        b--;
        c--;
        ps[i] = bred(ps[b],ps[c]);
    }
    cout << ps[a+1].ag;
    return 0;
}