結果
| 問題 |
No.1512 作文
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2021-05-22 04:48:16 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 56 ms / 2,000 ms |
| コード長 | 1,761 bytes |
| コンパイル時間 | 2,007 ms |
| コンパイル使用メモリ | 178,704 KB |
| 実行使用メモリ | 9,508 KB |
| 最終ジャッジ日時 | 2024-10-10 10:39:48 |
| 合計ジャッジ時間 | 3,614 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 38 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
#define SZ(x) (int)(x).size()
#define REP(i,n) for(int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REPR(i,n) for(int i=(n)-1;i>=0;i--)
#define ALL(s) (s).begin(), (s).end()
#define so(V) sort(ALL(V))
#define rev(V) reverse(ALL(V))
#define uni(v) v.erase( unique(ALL(v)) , v.end());
typedef long long unsigned int llu;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<bool> vb;
typedef vector<vi> vvi;
const double EPS = 1e-9;
const int MOD = 1e9 + 7;
const int INF = (1 << 29);
const ll LINF = 1e18;
const double PI = acos(-1);
template<typename T>
vector<T> make_v(size_t a) { return vector<T>(a); }
template<typename T, typename... Ts>
auto make_v(size_t a, Ts... ts) {
return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));
}
template <typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type
fill_v(T& t, const V& v) { t = v; }
template<typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type
fill_v(T& t, const V& v) {
for (auto& e : t) fill_v(e, v);
}
template<class T> bool chmax(T& a, const T& b) {
if (a < b) { a = b; return 1; }
return 0;
}
template<class T> bool chmin(T& a, const T& b) {
if (a > b) { a = b; return 1; }
return 0;
}
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
int N;
cin >> N;
vi dp(26, 0);
dp[0] = 0;
vector<string> VS(N);
REP(i, N) {
cin >> VS[i];
}
so(VS);
REP(i, N) {
bool flag = true;
REP(j, SZ(VS[i]) - 1) {
if (VS[i][j + 1] < VS[i][j])flag = false;
}
if (!flag)continue;
chmax(dp[VS[i][SZ(VS[i]) - 1] - 'a'], dp[VS[i][0] - 'a'] + SZ(VS[i]));
REP(j, 25) {
chmax(dp[j + 1], dp[j]);
}
}
cout << dp[25] << endl;
return 0;
}