結果
| 問題 |
No.1512 作文
|
| コンテスト | |
| ユーザー |
Manuel1024
|
| 提出日時 | 2022-01-12 22:55:12 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 79 ms / 2,000 ms |
| コード長 | 1,247 bytes |
| コンパイル時間 | 1,163 ms |
| コンパイル使用メモリ | 83,352 KB |
| 実行使用メモリ | 38,608 KB |
| 最終ジャッジ日時 | 2024-11-15 15:31:21 |
| 合計ジャッジ時間 | 3,516 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 38 |
ソースコード
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
using namespace std;
struct tup{
int s;
int e;
int len;
tup(int s, int e, int len): s(s), e(e), len(len){}
bool operator<(const tup &other) const {
if(this->e != other.e) return this->e < other.e;
else return this->s < other.s;
};
};
int main(){
int n;
cin >> n;
vector<string> s(n);
for(auto &p: s) cin >> p;
vector<tup> t;
for(auto &it: s){
bool isgood = true;
for(int i = 1; i < it.size(); i++){
if(it[i-1] > it[i]) isgood = false;
}
if(isgood) t.emplace_back(it[0]-'a', it.back()-'a', it.size());
}
sort(t.begin(), t.end());
vector<vector<int>> dp(t.size()+1, vector<int>(26, -(1 << 30)));
for(int i = 0; i < t.size(); i++){
dp[i][t[i].e] = max(dp[i][t[i].e], t[i].len);
if(i > 0){
for(int j = 0; j <= t[i].s; j++) dp[i][t[i].e] = max(dp[i][t[i].e], dp[i-1][j]+t[i].len);
}
for(int j = 0; j < 26; j++){
dp[i+1][j] = max(dp[i+1][j], dp[i][j]);
}
}
int ans = 0;
for(int i = 0; i < 26; i++) ans = max(ans, dp[t.size()][i]);
cout << ans << endl;
return 0;
}
Manuel1024