結果
| 問題 |
No.1512 作文
|
| コンテスト | |
| ユーザー |
rana
|
| 提出日時 | 2021-09-10 22:48:19 |
| 言語 | C++17(clang) (17.0.6 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 72 ms / 2,000 ms |
| コード長 | 1,020 bytes |
| コンパイル時間 | 1,646 ms |
| コンパイル使用メモリ | 131,288 KB |
| 実行使用メモリ | 11,600 KB |
| 最終ジャッジ日時 | 2024-06-12 02:22:55 |
| 合計ジャッジ時間 | 2,919 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 38 |
ソースコード
#include <algorithm>
#include <cstring>
#include <iostream>
#include <vector>
using namespace std;
bool good(string &s) {
char mx = 'a';
for (char& c : s) {
if (mx > c) return false;
mx = c;
}
return true;
}
int main(void) {
int n;
cin >> n;
vector<string> ok;
for (int i = 0; i < n; ++i) {
string s;
cin >> s;
if (good(s)) ok.push_back(s);
}
int m = ok.size();
long long dp[26];
memset(dp, 0, sizeof(dp));
sort(ok.begin(), ok.end(), [](string &x, string &y){
if (x.back() != y.back()) return x.back() < y.back();
return x < y;
});
for (int i = 0; i < m; ++i) {
int from = dp[ok[i].front() - 'a'];
int to = ok[i].back() - 'a';
for (int j = to; j < 26; ++j) {
dp[j] = max(dp[j], from + (long long)ok[i].size());
}
}
long long ans = 0;
for (int i = 0; i < 26; ++i) {
ans = max(ans, dp[i]);
}
cout << ans << endl;
}
rana