Submission #7986025


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();

    cin >> s >> t;

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

    int ans1 = calc(3*cnts);

    int ans2 = calc(4*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 600
Code Size 1940 Byte
Status AC
Exec Time 127 ms
Memory 40860 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 600 / 600
Status
AC × 3
AC × 70
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 16 ms 39296 KB
a02 AC 16 ms 39296 KB
a03 AC 16 ms 39296 KB
b04 AC 16 ms 39296 KB
b05 AC 16 ms 39296 KB
b06 AC 16 ms 39296 KB
b07 AC 16 ms 39296 KB
b08 AC 16 ms 39296 KB
b09 AC 16 ms 39296 KB
b10 AC 16 ms 39296 KB
b11 AC 16 ms 39296 KB
b12 AC 68 ms 40860 KB
b13 AC 116 ms 40860 KB
b14 AC 68 ms 40860 KB
b15 AC 67 ms 39964 KB
b16 AC 65 ms 39964 KB
b17 AC 68 ms 40860 KB
b18 AC 67 ms 40860 KB
b19 AC 65 ms 39964 KB
b20 AC 70 ms 40860 KB
b21 AC 118 ms 40860 KB
b22 AC 108 ms 40860 KB
b23 AC 118 ms 40860 KB
b24 AC 65 ms 39964 KB
b25 AC 70 ms 40860 KB
b26 AC 64 ms 39964 KB
b27 AC 117 ms 40860 KB
b28 AC 119 ms 40860 KB
b29 AC 127 ms 40860 KB
b30 AC 127 ms 40860 KB
b31 AC 120 ms 40860 KB
b32 AC 50 ms 40860 KB
b33 AC 67 ms 40860 KB
b34 AC 67 ms 40860 KB
b35 AC 110 ms 40860 KB
b36 AC 65 ms 40348 KB
b37 AC 71 ms 40860 KB
b38 AC 71 ms 40860 KB
b39 AC 118 ms 40860 KB
b40 AC 70 ms 40860 KB
b41 AC 71 ms 40860 KB
b42 AC 117 ms 40860 KB
b43 AC 122 ms 40860 KB
b44 AC 71 ms 40860 KB
b45 AC 121 ms 40860 KB
b46 AC 121 ms 40860 KB
b47 AC 76 ms 40860 KB
b48 AC 71 ms 40348 KB
b49 AC 72 ms 40860 KB
b50 AC 72 ms 40860 KB
b51 AC 126 ms 40860 KB
b52 AC 72 ms 40860 KB
b53 AC 123 ms 40860 KB
b54 AC 71 ms 40860 KB
b55 AC 72 ms 40860 KB
b56 AC 65 ms 39964 KB
b57 AC 64 ms 39964 KB
b58 AC 26 ms 39504 KB
b59 AC 16 ms 39296 KB
b60 AC 27 ms 39584 KB
b61 AC 19 ms 39424 KB
b62 AC 23 ms 39552 KB
b63 AC 64 ms 39964 KB
b64 AC 68 ms 40860 KB
b65 AC 71 ms 40860 KB
b66 AC 118 ms 40860 KB
b67 AC 115 ms 40860 KB
b68 AC 69 ms 40860 KB
b69 AC 65 ms 40860 KB
b70 AC 112 ms 40860 KB