結果
問題 |
No.1512 作文
|
ユーザー |
|
提出日時 | 2021-05-21 23:40:20 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 122 ms / 2,000 ms |
コード長 | 760 bytes |
コンパイル時間 | 2,112 ms |
コンパイル使用メモリ | 183,984 KB |
実行使用メモリ | 57,928 KB |
最終ジャッジ日時 | 2024-10-10 10:16:41 |
合計ジャッジ時間 | 4,283 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 38 |
ソースコード
#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>; int main() { int n; cin >> n; vector<string> s(n); rep(i, n) cin >> s[i]; sort(s.begin(), s.end()); vector<vector<ll>> dp(n + 1, vector<ll>(26)); rep(i, n) { rep(j, 26) dp[i + 1][j] = dp[i][j]; string t = s[i]; sort(t.begin(), t.end()); if (s[i] != t) continue; int m = s[i].size(); int next = *(s[i].rbegin()) - 'a'; for (int j = 0; j <= (s[i][0] - 'a'); j++) { dp[i + 1][next] = max(dp[i + 1][next], dp[i][j] + m); } } ll ans = 0; rep(i, 26) ans = max(ans, dp[n][i]); cout << ans << endl; }