結果
問題 |
No.1512 作文
|
ユーザー |
|
提出日時 | 2024-01-02 16:55:23 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 61 ms / 2,000 ms |
コード長 | 866 bytes |
コンパイル時間 | 2,100 ms |
コンパイル使用メモリ | 181,244 KB |
実行使用メモリ | 14,980 KB |
最終ジャッジ日時 | 2024-09-27 17:48:12 |
合計ジャッジ時間 | 4,212 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 38 |
ソースコード
#include <bits/stdc++.h> using namespace std; #define ll long long #define all(x) x.begin(),x.end() #define rep(i,a,b) for(int i=a;i<=b;i++) #define each(a,x) for (auto& x: a) const char nl = '\n'; bool good(string s){ string t = s; sort(all(s)); return s == t; } void solve(){ int n; cin >> n; vector<vector<int>> a; while (n--){ string s; cin >> s; if (good(s)){ a.push_back({s[0] - 'a', s.back() - 'a', (int) s.size()}); } } vector<int> dp(26); sort(all(a)); each(a,v){ int st = v[0], ed = v[1], len = v[2]; dp[ed] = max(dp[ed], dp[st] + len); rep(i,0,24) dp[i+1] = max(dp[i+1], dp[i]); } cout << dp.back() << nl; } int main(){ ios_base::sync_with_stdio(false); cin.tie(NULL); int t = 1;// cin >> t; while (t--){ solve(); } }