結果
問題 | No.1512 作文 |
ユーザー | nok0 |
提出日時 | 2021-05-18 23:30:52 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 79 ms / 2,000 ms |
コード長 | 530 bytes |
コンパイル時間 | 2,549 ms |
コンパイル使用メモリ | 208,740 KB |
最終ジャッジ日時 | 2025-01-21 13:46:58 |
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 38 |
ソースコード
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; vector<string> s; for(int i = 0; i < n; i++) { string x; cin >> x; auto y = x; sort(y.begin(), y.end()); if(x == y) s.push_back(x); } sort(s.begin(), s.end()); vector res(26, 0); for(auto &v : s) { int f = v.front() - 'a'; int b = v.back() - 'a'; int tmp = 0; for(int i = 0; i <= f; i++) tmp = max(tmp, res[i]); res[b] = max(res[b], tmp + (int)v.size()); } cout << *max_element(res.begin(), res.end()) << '\n'; return 0; }