提出 #7986025


ソースコード 拡げる

#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;
}

提出情報

提出日時
問題 F - Strings of Eternity
ユーザ ToMmyDong
言語 C++14 (GCC 5.4.1)
得点 600
コード長 1940 Byte
結果 AC
実行時間 127 ms
メモリ 40860 KiB

ジャッジ結果

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