Submission #7985515


Source Code Expand

Copy
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i,n) for(int i=0;i<n;i++)
#define REP1(i,n) for(int i=1;i<=n;i++)
#define SZ(i) int(i.size())
#ifdef tmd
#define IOS()
#define debug(...) fprintf(stderr,"%s - %d (%s) = ",__PRETTY_FUNCTION__,__LINE__,#__VA_ARGS__);_do(__VA_ARGS__);
template<typename T> void _do(T &&x){cerr<<x<<endl;}
template<typename T, typename ...S> void _do(T &&x, S &&...y){cerr<<x<<", ";_do(y...);}
#else
#define IOS() ios_base::sync_with_stdio(0);cin.tie(0);
#define endl '\n'
#define debug(...)
#endif

const int MAXN = 5000006;
const ll MOD = 1000000007;

string s, t;

int z[MAXN], bst, dp[MAXN];
int cnts;

inline char sat (int pos) {
    if (pos < SZ(t)) {
        return t[pos];
    } else if (pos == SZ(t)) {
        return '@';
    } else {
        return s[(pos-SZ(t)-1)%SZ(s)];
    }
}
int calc (int ss) {
    memset(z, 0, sizeof(z));
    memset(dp, 0, sizeof(dp));
    bst = 0;

    int sz = SZ(t) + 1 + ss * SZ(s);
    debug(sz);

    REP1 (i, sz-1) {
        if (i % 100000 == 0) {
            debug(i);
        }
        if (bst+z[bst] > i) {
            z[i] = min(bst+z[bst]-i, z[i-bst]);
        }

        while (i+z[i] < sz && sat(z[i]) == sat(i+z[i])) {
            z[i]++;
        }
        if (i+z[i] >= bst+z[bst]) {
            bst = i;
        }
    }

    int ret = 0;
    for (int i=SZ(t)+1; i<sz; i++) {
        if (z[i] == SZ(t)) {
            dp[i] = dp[i-SZ(t)] + 1;
            ret = max(ret, dp[i]);
        }
    }

    return ret;
}
/*********************GoodLuck***********************/
int main () {
    IOS();
    #ifdef tmd
    for (int i=0; i<500000; i++) {
        s += char('a' + rand()%26);
    }
    for (int i=0; i<2; i++) {
        t += char('a');
    }
    cout << SZ(s) << ", " << SZ(t) << endl;
    #else
    cin >> s >> t;
    #endif

    cnts = (SZ(t)+SZ(s)-1)/SZ(s);
    debug(cnts);

    int ans1 = calc(2*cnts);

    int ans2 = calc(3*cnts);

    if (ans2 > ans1) {
        cout << -1 << endl;
    } else {
        cout << ans1 << endl;
    }
    return 0;
}

Submission Info

Submission Time
Task F - Strings of Eternity
User ToMmyDong
Language C++14 (GCC 5.4.1)
Score 0
Code Size 2165 Byte
Status WA
Exec Time 98 ms
Memory 40860 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 0 / 600
Status
AC × 3
AC × 66
WA × 4
Set Name Test Cases
Sample a01, a02, a03
All a01, a02, a03, b04, b05, b06, b07, b08, b09, b10, b11, b12, b13, b14, b15, b16, b17, b18, b19, b20, b21, b22, b23, b24, b25, b26, b27, b28, b29, b30, b31, b32, b33, b34, b35, b36, b37, b38, b39, b40, b41, b42, b43, b44, b45, b46, b47, b48, b49, b50, b51, b52, b53, b54, b55, b56, b57, b58, b59, b60, b61, b62, b63, b64, b65, b66, b67, b68, b69, b70
Case Name Status Exec Time Memory
a01 AC 17 ms 39296 KB
a02 AC 16 ms 39296 KB
a03 AC 16 ms 39296 KB
b04 AC 17 ms 39296 KB
b05 AC 17 ms 39296 KB
b06 AC 17 ms 39296 KB
b07 AC 17 ms 39296 KB
b08 AC 17 ms 39296 KB
b09 AC 17 ms 39296 KB
b10 AC 17 ms 39296 KB
b11 AC 17 ms 39296 KB
b12 AC 55 ms 40860 KB
b13 AC 89 ms 40860 KB
b14 AC 55 ms 40860 KB
b15 AC 54 ms 39964 KB
b16 AC 52 ms 39964 KB
b17 AC 55 ms 40860 KB
b18 AC 55 ms 40860 KB
b19 AC 52 ms 39964 KB
b20 AC 57 ms 40860 KB
b21 AC 92 ms 40860 KB
b22 AC 83 ms 40860 KB
b23 AC 91 ms 40860 KB
b24 AC 52 ms 39964 KB
b25 WA 57 ms 40860 KB
b26 AC 51 ms 39964 KB
b27 AC 91 ms 40860 KB
b28 AC 92 ms 40860 KB
b29 AC 98 ms 40860 KB
b30 AC 98 ms 40860 KB
b31 AC 94 ms 40860 KB
b32 AC 43 ms 40860 KB
b33 AC 54 ms 40860 KB
b34 AC 54 ms 40860 KB
b35 AC 84 ms 40860 KB
b36 AC 53 ms 40348 KB
b37 AC 58 ms 40860 KB
b38 WA 58 ms 40860 KB
b39 AC 92 ms 40860 KB
b40 AC 57 ms 40860 KB
b41 WA 58 ms 40860 KB
b42 AC 91 ms 40860 KB
b43 AC 94 ms 40860 KB
b44 AC 59 ms 40860 KB
b45 AC 94 ms 40860 KB
b46 AC 94 ms 40860 KB
b47 AC 62 ms 40860 KB
b48 AC 57 ms 40348 KB
b49 AC 60 ms 40860 KB
b50 AC 59 ms 40860 KB
b51 AC 97 ms 40860 KB
b52 AC 59 ms 40860 KB
b53 AC 95 ms 40860 KB
b54 WA 58 ms 40860 KB
b55 AC 59 ms 40860 KB
b56 AC 52 ms 39964 KB
b57 AC 51 ms 39964 KB
b58 AC 24 ms 39504 KB
b59 AC 17 ms 39296 KB
b60 AC 25 ms 39584 KB
b61 AC 19 ms 39424 KB
b62 AC 22 ms 39552 KB
b63 AC 51 ms 39964 KB
b64 AC 56 ms 40860 KB
b65 AC 59 ms 40860 KB
b66 AC 92 ms 40860 KB
b67 AC 89 ms 40860 KB
b68 AC 56 ms 40860 KB
b69 AC 53 ms 40860 KB
b70 AC 86 ms 40860 KB