結果

問題 No.2606 Mirror Relay
ユーザー TairitsuMeowTairitsuMeow
提出日時 2024-01-12 23:16:38
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 50 ms / 2,000 ms
コード長 1,492 bytes
コンパイル時間 1,501 ms
コンパイル使用メモリ 168,936 KB
実行使用メモリ 62,496 KB
最終ジャッジ日時 2024-01-12 23:16:43
合計ジャッジ時間 3,599 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
11,980 KB
testcase_01 AC 3 ms
11,980 KB
testcase_02 AC 3 ms
11,980 KB
testcase_03 AC 3 ms
11,980 KB
testcase_04 AC 3 ms
11,980 KB
testcase_05 AC 3 ms
11,980 KB
testcase_06 AC 3 ms
11,980 KB
testcase_07 AC 3 ms
11,980 KB
testcase_08 AC 3 ms
11,980 KB
testcase_09 AC 3 ms
11,980 KB
testcase_10 AC 3 ms
11,980 KB
testcase_11 AC 3 ms
11,980 KB
testcase_12 AC 3 ms
11,980 KB
testcase_13 AC 4 ms
11,980 KB
testcase_14 AC 3 ms
11,980 KB
testcase_15 AC 3 ms
11,980 KB
testcase_16 AC 4 ms
11,980 KB
testcase_17 AC 3 ms
11,980 KB
testcase_18 AC 3 ms
11,980 KB
testcase_19 AC 3 ms
12,364 KB
testcase_20 AC 3 ms
12,236 KB
testcase_21 AC 3 ms
12,236 KB
testcase_22 AC 3 ms
12,236 KB
testcase_23 AC 3 ms
12,236 KB
testcase_24 AC 3 ms
12,236 KB
testcase_25 AC 3 ms
12,108 KB
testcase_26 AC 3 ms
12,108 KB
testcase_27 AC 3 ms
12,236 KB
testcase_28 AC 3 ms
12,108 KB
testcase_29 AC 3 ms
11,980 KB
testcase_30 AC 3 ms
11,980 KB
testcase_31 AC 3 ms
11,980 KB
testcase_32 AC 3 ms
11,980 KB
testcase_33 AC 4 ms
11,980 KB
testcase_34 AC 3 ms
11,980 KB
testcase_35 AC 3 ms
11,980 KB
testcase_36 AC 3 ms
11,980 KB
testcase_37 AC 3 ms
11,980 KB
testcase_38 AC 3 ms
11,980 KB
testcase_39 AC 7 ms
14,396 KB
testcase_40 AC 6 ms
14,392 KB
testcase_41 AC 6 ms
14,392 KB
testcase_42 AC 7 ms
14,380 KB
testcase_43 AC 7 ms
14,404 KB
testcase_44 AC 6 ms
14,404 KB
testcase_45 AC 7 ms
14,400 KB
testcase_46 AC 7 ms
14,396 KB
testcase_47 AC 6 ms
14,392 KB
testcase_48 AC 7 ms
14,400 KB
testcase_49 AC 18 ms
27,260 KB
testcase_50 AC 20 ms
28,416 KB
testcase_51 AC 20 ms
30,992 KB
testcase_52 AC 17 ms
25,192 KB
testcase_53 AC 20 ms
31,100 KB
testcase_54 AC 19 ms
27,780 KB
testcase_55 AC 29 ms
39,568 KB
testcase_56 AC 18 ms
27,772 KB
testcase_57 AC 17 ms
25,840 KB
testcase_58 AC 22 ms
32,908 KB
testcase_59 AC 7 ms
14,520 KB
testcase_60 AC 7 ms
14,500 KB
testcase_61 AC 6 ms
14,428 KB
testcase_62 AC 7 ms
14,448 KB
testcase_63 AC 7 ms
14,692 KB
testcase_64 AC 7 ms
14,448 KB
testcase_65 AC 6 ms
14,528 KB
testcase_66 AC 7 ms
14,440 KB
testcase_67 AC 7 ms
14,456 KB
testcase_68 AC 7 ms
14,476 KB
testcase_69 AC 50 ms
62,496 KB
testcase_70 AC 3 ms
11,980 KB
testcase_71 AC 4 ms
11,980 KB
testcase_72 AC 3 ms
11,980 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

// Problem: No.2606 Mirror Relay
// Contest: yukicoder
// URL: https://yukicoder.me/problems/no/2606
// Memory Limit: 512 MB
// Time Limit: 2000 ms

#include<bits/stdc++.h>
#define debug(x) cerr<<(#x)<<" "<<(x)<<endl
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
#define pii pair<ll,ll>
#define rep(i,a,b) for(ll i=(a);i<=(b);++i)
#define per(i,a,b) for(ll i=(a);i>=(b);--i)
using namespace std;
bool Mbe; 
ll read(){
	ll x=0,f=1;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
	return x*f;
}
void write(ll x){
	if(x<0)putchar('-'),x=-x;
	if(x>9)write(x/10);
	putchar(x%10+'0');
}
const ll N=1e6+9;
ll n,p,q,fail[N],cnt[N],len[N],tot,lst,ch[N][26],pos[N],sum[N];
char s[N];
ll New(ll x){
    len[++tot]=x;
    return tot;
}
ll Fail(ll x,ll i){
    while(s[i-len[x]-1]!=s[i])x=fail[x];
    return x;
}
bool Med;
int main(){
	cerr<<fabs(&Med-&Mbe)/1048576.0<<"MB\n";
	scanf("%s",s+1);
	n=strlen(s+1);
	reverse(s+1,s+n+1);
	s[0]=-1,fail[0]=1,lst=0;
    len[0]=0,len[1]=-1,tot=1;
    rep(i,1,n){
        ll v=s[i]-'a';
        p=Fail(lst,i);
        if(!ch[p][v]){
            q=New(len[p]+2);
            fail[q]=ch[Fail(fail[p],i)][v]; 
            ch[p][v]=q;
        }
        lst=ch[p][v];
        ++cnt[lst];
        pos[i]=lst;
    }
    per(i,tot,1)cnt[fail[i]]+=cnt[i];
    rep(i,1,tot)sum[i]=cnt[i]*len[i]+sum[fail[i]];
    write(*max_element(sum+1,sum+tot+1));
	return 0;
}
0