提出 #7564431


ソースコード 拡げる

#include <bits/stdc++.h>
 
using namespace std;
typedef long long LL;
typedef pair<int,int> pii;
typedef int ftype;
typedef complex<ftype> point;
 
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second 
#define debug(x)  do{cerr<<#x<<": "<<x<<"\n";}while(0)
#define debugv(x) do{cerr<<#x<<": ";for(auto&e: (x))cerr<<e<<" ";cerr<<"\n";}while(0)
#define fori(i, n) for (int i = 0; i < (int)(n); ++i)
#define forn(i, n) for (int i = 1; i <= (int)(n); ++i)
#define ford(i, n) for (int i = (int)(n); i >= 0; --i)
#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)
#define RETURN(x) do{cout << x << '\n'; return 0;}while(0)
#define FIRSTWIN do{cout << "Monocarp\n"; return 0;}while(0)
#define SECONDWIN do{cout << "Bicarp\n"; return 0;}while(0)

const int MAXN = 5e3+4;
const int MOD = 1e9+7;

int N;
char S[MAXN];
int z[MAXN];

int ans;
void zfunction(char *s, char *end) {
    int n = end-s;
    for (int i = 0; i < n; i++) z[i] = 0;

    for (int i = 1, l = 0, r = 0; i < n; ++i) {
        if (i <= r)
            z[i] = min (r - i + 1, z[i - l]);
        while (i + z[i] < n && s[z[i]] == s[i + z[i]])
            ++z[i];
        if (i + z[i] - 1 > r)
            l = i, r = i + z[i] - 1;
    }

    for (int i = 1; i < n; ++i) 
        ans = max(ans, min(i, z[i]));
}

int main() {
#ifdef OJ
    freopen("input.txt", "rt", stdin);
    //freopen("output.txt", "wt", stdout);
#endif
    ios::sync_with_stdio(false);
    cin.tie(0);

    cin >> N >> S;
    char *end = S+N;
    for (char *s = S; s+1 != end; s++) 
        zfunction(s,end);

    cout << ans << '\n';
    return 0;
}

提出情報

提出日時
問題 E - Who Says a Pun?
ユーザ tuananh
言語 C++14 (GCC 5.4.1)
得点 500
コード長 1703 Byte
結果 AC
実行時間 116 ms
メモリ 256 KiB

ジャッジ結果

セット名 Sample All
得点 / 配点 0 / 0 500 / 500
結果
AC × 3
AC × 70
セット名 テストケース
Sample 00-sample-00, 00-sample-01, 00-sample-02
All 00-sample-00, 00-sample-01, 00-sample-02, 01-handmade-03, 01-handmade-04, 01-handmade-05, 01-handmade-06, 01-handmade-07, 01-handmade-08, 01-handmade-09, 01-handmade-10, 01-handmade-11, 01-handmade-12, 02-binary-13, 02-binary-14, 02-binary-15, 02-binary-16, 02-binary-17, 02-binary-18, 02-binary-19, 02-binary-20, 02-binary-21, 02-binary-22, 02-binary-23, 03-BigRandom-24, 03-BigRandom-25, 03-BigRandom-26, 03-BigRandom-27, 03-BigRandom-28, 03-BigRandom-29, 03-BigRandom-30, 03-BigRandom-31, 03-BigRandom-32, 03-BigRandom-33, 03-BigRandom-34, 03-BigRandom-35, 03-BigRandom-36, 03-BigRandom-37, 03-BigRandom-38, 03-BigRandom-39, 03-BigRandom-40, 03-BigRandom-41, 03-BigRandom-42, 03-BigRandom-43, 03-BigRandom-44, 03-BigRandom-45, 03-BigRandom-46, 03-BigRandom-47, 03-BigRandom-48, 03-BigRandom-49, 03-BigRandom-50, 03-BigRandom-51, 03-BigRandom-52, 03-BigRandom-53, 03-BigRandom-54, 04-zero-55, 04-zero-56, 05-AllRandom-57, 05-AllRandom-58, 05-AllRandom-59, 05-AllRandom-60, 05-AllRandom-61, 05-AllRandom-62, 05-AllRandom-63, 05-AllRandom-64, 05-AllRandom-65, 05-AllRandom-66, 05-AllRandom-67, 05-AllRandom-68, 05-AllRandom-69
ケース名 結果 実行時間 メモリ
00-sample-00 AC 1 ms 256 KiB
00-sample-01 AC 1 ms 256 KiB
00-sample-02 AC 1 ms 256 KiB
01-handmade-03 AC 63 ms 256 KiB
01-handmade-04 AC 69 ms 256 KiB
01-handmade-05 AC 51 ms 256 KiB
01-handmade-06 AC 51 ms 256 KiB
01-handmade-07 AC 51 ms 256 KiB
01-handmade-08 AC 116 ms 256 KiB
01-handmade-09 AC 87 ms 256 KiB
01-handmade-10 AC 70 ms 256 KiB
01-handmade-11 AC 65 ms 256 KiB
01-handmade-12 AC 67 ms 256 KiB
02-binary-13 AC 77 ms 256 KiB
02-binary-14 AC 94 ms 256 KiB
02-binary-15 AC 70 ms 256 KiB
02-binary-16 AC 104 ms 256 KiB
02-binary-17 AC 105 ms 256 KiB
02-binary-18 AC 90 ms 256 KiB
02-binary-19 AC 56 ms 256 KiB
02-binary-20 AC 68 ms 256 KiB
02-binary-21 AC 64 ms 256 KiB
02-binary-22 AC 57 ms 256 KiB
02-binary-23 AC 54 ms 256 KiB
03-BigRandom-24 AC 43 ms 256 KiB
03-BigRandom-25 AC 43 ms 256 KiB
03-BigRandom-26 AC 41 ms 256 KiB
03-BigRandom-27 AC 49 ms 256 KiB
03-BigRandom-28 AC 44 ms 256 KiB
03-BigRandom-29 AC 47 ms 256 KiB
03-BigRandom-30 AC 44 ms 256 KiB
03-BigRandom-31 AC 45 ms 256 KiB
03-BigRandom-32 AC 49 ms 256 KiB
03-BigRandom-33 AC 42 ms 256 KiB
03-BigRandom-34 AC 47 ms 256 KiB
03-BigRandom-35 AC 40 ms 256 KiB
03-BigRandom-36 AC 49 ms 256 KiB
03-BigRandom-37 AC 46 ms 256 KiB
03-BigRandom-38 AC 43 ms 256 KiB
03-BigRandom-39 AC 48 ms 256 KiB
03-BigRandom-40 AC 43 ms 256 KiB
03-BigRandom-41 AC 48 ms 256 KiB
03-BigRandom-42 AC 46 ms 256 KiB
03-BigRandom-43 AC 43 ms 256 KiB
03-BigRandom-44 AC 43 ms 256 KiB
03-BigRandom-45 AC 47 ms 256 KiB
03-BigRandom-46 AC 40 ms 256 KiB
03-BigRandom-47 AC 49 ms 256 KiB
03-BigRandom-48 AC 44 ms 256 KiB
03-BigRandom-49 AC 44 ms 256 KiB
03-BigRandom-50 AC 49 ms 256 KiB
03-BigRandom-51 AC 48 ms 256 KiB
03-BigRandom-52 AC 48 ms 256 KiB
03-BigRandom-53 AC 49 ms 256 KiB
03-BigRandom-54 AC 48 ms 256 KiB
04-zero-55 AC 1 ms 256 KiB
04-zero-56 AC 1 ms 256 KiB
05-AllRandom-57 AC 46 ms 256 KiB
05-AllRandom-58 AC 42 ms 256 KiB
05-AllRandom-59 AC 47 ms 256 KiB
05-AllRandom-60 AC 45 ms 256 KiB
05-AllRandom-61 AC 44 ms 256 KiB
05-AllRandom-62 AC 43 ms 256 KiB
05-AllRandom-63 AC 41 ms 256 KiB
05-AllRandom-64 AC 42 ms 256 KiB
05-AllRandom-65 AC 43 ms 256 KiB
05-AllRandom-66 AC 44 ms 256 KiB
05-AllRandom-67 AC 43 ms 256 KiB
05-AllRandom-68 AC 47 ms 256 KiB
05-AllRandom-69 AC 47 ms 256 KiB