結果
| 問題 |
No.1512 作文
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2021-05-21 22:56:25 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,258 bytes |
| コンパイル時間 | 1,788 ms |
| コンパイル使用メモリ | 178,548 KB |
| 実行使用メモリ | 9,548 KB |
| 最終ジャッジ日時 | 2024-10-10 09:41:15 |
| 合計ジャッジ時間 | 3,319 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 21 WA * 17 |
ソースコード
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;
template <class T, class U>
void chmin(T& t, const U& u) {
if (t > u) t = u;
}
template <class T, class U>
void chmax(T& t, const U& u) {
if (t < u) t = u;
}
int main() {
int n;
cin >> n;
vector<string> s(n);
rep(i, n) cin >> s[i];
vector<vector<ll>> dist(26, vector<ll>(26));
vector<ll> plus(26);
rep(i, n) {
string t = s[i];
sort(t.begin(), t.end());
if (s[i] != t) continue;
int m = s[i].size();
int start = *(s[i].begin()) - 'a';
int end = *(s[i].rbegin()) - 'a';
if (start == end) {
chmax(plus[start], m);
} else {
for (int j = 0; j <= start; j++) {
chmax(dist[j][end], m);
}
}
}
ll ans = 0;
rep(i, 26) chmax(ans, plus[i]);
rep(i, 26) rep(j, 26) dist[i][j] += plus[i];
rep(k, 26) rep(i, 26) rep(j, 26) {
if (i < j) chmax(ans, dist[i][j]);
if (i >= k || k >= j) continue;
dist[i][j] = max(dist[i][j], dist[i][k] + dist[k][j]);
chmax(ans, dist[i][j] + plus[j]);
}
cout << ans << endl;
}