結果
| 問題 |
No.1512 作文
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2021-05-21 21:29:58 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 73 ms / 2,000 ms |
| コード長 | 569 bytes |
| コンパイル時間 | 2,377 ms |
| コンパイル使用メモリ | 205,448 KB |
| 最終ジャッジ日時 | 2025-01-21 14:22:30 |
|
ジャッジサーバーID (参考情報) |
judge2 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 38 |
ソースコード
#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++){
int mx=0;
for(int j=0;j<=S[i].front()-'a';j++) mx=max(mx,dp[j]);
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'],mx+(int)S[i].size());
ans=max(ans,dp[S[i].back()-'a']);
home:;
}
cout<<ans<<endl;
}