結果
| 問題 |
No.1512 作文
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2021-11-27 17:08:37 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,107 bytes |
| コンパイル時間 | 1,737 ms |
| コンパイル使用メモリ | 177,100 KB |
| 実行使用メモリ | 6,948 KB |
| 最終ジャッジ日時 | 2024-06-30 08:08:11 |
| 合計ジャッジ時間 | 4,067 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 21 WA * 17 |
ソースコード
#include<bits/stdc++.h>
#include<iostream>
using namespace std;
using LL = long long;
using P = pair<int,int>;
using Graph = vector<vector<int>>;
const int INF = 1 << 29;
const long long LINF = 1LL << 60;
#define all(x) (x).begin(), (x).end()
#define rep(i,n) for(int i = 0; i < (n); ++i)
template<class T>void chmin(T&a, T b){if(a > b) a = b;}
template<class T>void chmax(T&a, T b){if(a < b) a = b;}
int main(){
LL N; cin >> N;
vector<vector<int>> tmp(26, vector<int>(26, 0));
for(LL i = 0; i < N; ++i){
string S, T; cin >> S;
T = S;
sort(S.begin(), S.end());
if(T!=S) continue;
int a = S[0] - 'a', b = S[(int)S.size()-1] - 'a';
tmp[a][b] = max(tmp[a][b], (int)S.size());
}
/*
for(int i = 0; i < 26; ++i){
for(int j = 0; j < 26; ++j){
cout << tmp[i][j] << " ";
}
cout << endl;
}
*/
vector<long long> dp(26, 0);
dp[0] = 0;
for(int i = 0; i < 26; ++i){
for(int j = 0; j < 26; ++j){
if(j<i) continue;
chmax(dp[j], dp[i] + tmp[i][j]);
}
}
LL ans = 0;
for(int i = 0; i < 26; ++i){
//cout << dp[i] << endl;
ans = max(ans, dp[i]);
}
cout << ans << endl;
}