結果

問題 No.1512 作文
ユーザー shiomusubi496
提出日時 2021-05-21 21:28:05
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 506 bytes
コンパイル時間 2,340 ms
コンパイル使用メモリ 205,372 KB
最終ジャッジ日時 2025-01-21 14:18:34
ジャッジサーバーID
(参考情報)
judge2 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3 WA * 1
other AC * 26 WA * 12
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
#define int long long
using namespace std;
signed main(){
    int N; cin>>N;
    vector<string> S(N);
    for(int i=0;i<N;i++) cin>>S[i];
    sort(S.begin(),S.end());
    int ans=0;
    vector<int>dp(26);
    for(int i=0;i<N;i++){
        for(int j=0;j+1<S[i].size();j++) if(S[i][j]>S[i][j+1]) goto home;
        dp[S[i].back()-'a']=max(dp[S[i].back()-'a'],dp[S[i].front()-'a']+(int)S[i].size());
        ans=max(ans,dp[S[i].back()-'a']);
        home:;
    }
    cout<<ans<<endl;
}
0