Submission #7557143


Source Code Expand

Copy
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using VI = vector<ll>;
using VV = vector<VI>;
using VS = vector<string>;

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define rep(i,b) FOR(i, 0, b)
#define ALL(v) (v).begin(), (v).end()
#define p(s) cout<<(s)<<endl
#define p2(s, t) cout << (s) << " " << (t) << endl
#define br() p("")
#define pn(s) cout << (#s) << " " << (s) << endl
#define p_yes() p("YES")
#define p_no() p("NO")
#define pb(s) push_back(s)
#define SZ(x) ((int)(x).size())

void no(){p_no(); exit(0);}
void yes(){p_yes(); exit(0);}

const ll mod = 1e9 + 7;
const ll inf = 1e18;

vector<ll> Zalgo(const string &S) {
    int N = (int)S.size();
    VI res(N);
    res[0] = N;
    int i = 1, j = 0;
    while (i < N) {
        while (i+j < N && S[j] == S[i+j]) ++j;
        res[i] = j;
        if (j == 0) {++i; continue;}
        int k = 1;
        while (i+k < N && k+res[k] < j) res[i+k] = res[k], ++k;
        i += k, j -= k;
    }
    return res;
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);

    // input
    ll N; cin >> N;
    string s; cin >> s;

    ll ma = 0;
    rep(i, N){
      string t = s.substr(i);
      auto z = Zalgo(t);
      rep(j, t.size()){
        ll lcp = z[j];
        lcp = min(lcp, j-0);
        chmax(ma, lcp);
      }
    }

    p(ma);

    return 0;
}

Submission Info

Submission Time
Task E - Who Says a Pun?
User peroon
Language C++14 (GCC 5.4.1)
Score 500
Code Size 1579 Byte
Status
Exec Time 94 ms
Memory 384 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 500 / 500
Status
× 3
× 70
Set Name Test Cases
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
Case Name Status Exec Time Memory
00-sample-00 1 ms 256 KB
00-sample-01 1 ms 256 KB
00-sample-02 1 ms 256 KB
01-handmade-03 58 ms 384 KB
01-handmade-04 61 ms 256 KB
01-handmade-05 47 ms 256 KB
01-handmade-06 47 ms 256 KB
01-handmade-07 48 ms 384 KB
01-handmade-08 47 ms 384 KB
01-handmade-09 52 ms 256 KB
01-handmade-10 63 ms 384 KB
01-handmade-11 60 ms 384 KB
01-handmade-12 59 ms 256 KB
02-binary-13 69 ms 256 KB
02-binary-14 82 ms 256 KB
02-binary-15 64 ms 256 KB
02-binary-16 94 ms 256 KB
02-binary-17 94 ms 256 KB
02-binary-18 81 ms 256 KB
02-binary-19 50 ms 256 KB
02-binary-20 60 ms 256 KB
02-binary-21 55 ms 256 KB
02-binary-22 53 ms 256 KB
02-binary-23 46 ms 256 KB
03-BigRandom-24 41 ms 256 KB
03-BigRandom-25 40 ms 256 KB
03-BigRandom-26 39 ms 256 KB
03-BigRandom-27 47 ms 384 KB
03-BigRandom-28 43 ms 384 KB
03-BigRandom-29 45 ms 256 KB
03-BigRandom-30 43 ms 256 KB
03-BigRandom-31 43 ms 384 KB
03-BigRandom-32 47 ms 256 KB
03-BigRandom-33 41 ms 256 KB
03-BigRandom-34 44 ms 384 KB
03-BigRandom-35 39 ms 256 KB
03-BigRandom-36 47 ms 256 KB
03-BigRandom-37 43 ms 384 KB
03-BigRandom-38 40 ms 256 KB
03-BigRandom-39 45 ms 384 KB
03-BigRandom-40 42 ms 256 KB
03-BigRandom-41 45 ms 384 KB
03-BigRandom-42 43 ms 384 KB
03-BigRandom-43 41 ms 256 KB
03-BigRandom-44 42 ms 256 KB
03-BigRandom-45 46 ms 256 KB
03-BigRandom-46 39 ms 256 KB
03-BigRandom-47 47 ms 384 KB
03-BigRandom-48 42 ms 256 KB
03-BigRandom-49 42 ms 256 KB
03-BigRandom-50 47 ms 384 KB
03-BigRandom-51 45 ms 384 KB
03-BigRandom-52 46 ms 256 KB
03-BigRandom-53 47 ms 256 KB
03-BigRandom-54 45 ms 256 KB
04-zero-55 1 ms 256 KB
04-zero-56 1 ms 256 KB
05-AllRandom-57 46 ms 256 KB
05-AllRandom-58 43 ms 256 KB
05-AllRandom-59 47 ms 256 KB
05-AllRandom-60 45 ms 384 KB
05-AllRandom-61 45 ms 256 KB
05-AllRandom-62 44 ms 384 KB
05-AllRandom-63 42 ms 256 KB
05-AllRandom-64 42 ms 256 KB
05-AllRandom-65 43 ms 384 KB
05-AllRandom-66 44 ms 256 KB
05-AllRandom-67 44 ms 384 KB
05-AllRandom-68 48 ms 256 KB
05-AllRandom-69 48 ms 256 KB