提出 #7985515


ソースコード 拡げる

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

提出情報

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

ジャッジ結果

セット名 Sample All
得点 / 配点 0 / 0 0 / 600
結果
AC × 3
AC × 66
WA × 4
セット名 テストケース
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 17 ms 39296 KiB
a02 AC 16 ms 39296 KiB
a03 AC 16 ms 39296 KiB
b04 AC 17 ms 39296 KiB
b05 AC 17 ms 39296 KiB
b06 AC 17 ms 39296 KiB
b07 AC 17 ms 39296 KiB
b08 AC 17 ms 39296 KiB
b09 AC 17 ms 39296 KiB
b10 AC 17 ms 39296 KiB
b11 AC 17 ms 39296 KiB
b12 AC 55 ms 40860 KiB
b13 AC 89 ms 40860 KiB
b14 AC 55 ms 40860 KiB
b15 AC 54 ms 39964 KiB
b16 AC 52 ms 39964 KiB
b17 AC 55 ms 40860 KiB
b18 AC 55 ms 40860 KiB
b19 AC 52 ms 39964 KiB
b20 AC 57 ms 40860 KiB
b21 AC 92 ms 40860 KiB
b22 AC 83 ms 40860 KiB
b23 AC 91 ms 40860 KiB
b24 AC 52 ms 39964 KiB
b25 WA 57 ms 40860 KiB
b26 AC 51 ms 39964 KiB
b27 AC 91 ms 40860 KiB
b28 AC 92 ms 40860 KiB
b29 AC 98 ms 40860 KiB
b30 AC 98 ms 40860 KiB
b31 AC 94 ms 40860 KiB
b32 AC 43 ms 40860 KiB
b33 AC 54 ms 40860 KiB
b34 AC 54 ms 40860 KiB
b35 AC 84 ms 40860 KiB
b36 AC 53 ms 40348 KiB
b37 AC 58 ms 40860 KiB
b38 WA 58 ms 40860 KiB
b39 AC 92 ms 40860 KiB
b40 AC 57 ms 40860 KiB
b41 WA 58 ms 40860 KiB
b42 AC 91 ms 40860 KiB
b43 AC 94 ms 40860 KiB
b44 AC 59 ms 40860 KiB
b45 AC 94 ms 40860 KiB
b46 AC 94 ms 40860 KiB
b47 AC 62 ms 40860 KiB
b48 AC 57 ms 40348 KiB
b49 AC 60 ms 40860 KiB
b50 AC 59 ms 40860 KiB
b51 AC 97 ms 40860 KiB
b52 AC 59 ms 40860 KiB
b53 AC 95 ms 40860 KiB
b54 WA 58 ms 40860 KiB
b55 AC 59 ms 40860 KiB
b56 AC 52 ms 39964 KiB
b57 AC 51 ms 39964 KiB
b58 AC 24 ms 39504 KiB
b59 AC 17 ms 39296 KiB
b60 AC 25 ms 39584 KiB
b61 AC 19 ms 39424 KiB
b62 AC 22 ms 39552 KiB
b63 AC 51 ms 39964 KiB
b64 AC 56 ms 40860 KiB
b65 AC 59 ms 40860 KiB
b66 AC 92 ms 40860 KiB
b67 AC 89 ms 40860 KiB
b68 AC 56 ms 40860 KiB
b69 AC 53 ms 40860 KiB
b70 AC 86 ms 40860 KiB