結果
| 問題 |
No.1512 作文
|
| ユーザー |
y61mpnl
|
| 提出日時 | 2021-05-21 21:54:09 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 755 bytes |
| コンパイル時間 | 1,990 ms |
| コンパイル使用メモリ | 197,992 KB |
| 最終ジャッジ日時 | 2025-01-21 14:55:29 |
|
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 20 WA * 18 |
ソースコード
#include<bits/stdc++.h>
#define REP(i,b,e) for(int i=b;i<e;i++)
int main(){
int n;
std::cin >> n;
std::vector<std::string> ss;
REP(i, 0, n){
std::string s;
std::cin >> s;
bool ok = true;
REP(j, 0, s.size()-1){
if(s[j]>s[j+1]) ok = false;
}
if(ok) ss.push_back(s);
}
n = ss.size();
int self[26] = {}, links[26][26] = {};
REP(i, 0, n){
int fr = ss[i].front()-'a', bk = ss[i].back()-'a';
if(fr==bk){
self[fr] += ss[i].size();
}else{
links[fr][bk] = std::max<int>(links[fr][bk], ss[i].size());
}
}
int dist[26] = {};
REP(i, 0, 26) REP(j, i+1, 26) {
dist[j] = std::max(dist[j], dist[i] + self[i] + links[i][j]);
}
int ans = 0;
REP(i, 0, 26) ans = std::max(ans, dist[i]);
printf("%d\n", ans);
return 0;
}
y61mpnl