結果

問題 No.1512 作文
ユーザー milanis48663220milanis48663220
提出日時 2021-05-21 21:33:26
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 56 ms / 2,000 ms
コード長 1,379 bytes
コンパイル時間 1,574 ms
コンパイル使用メモリ 129,156 KB
実行使用メモリ 9,472 KB
最終ジャッジ日時 2024-04-18 14:42:57
合計ジャッジ時間 3,136 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 44 ms
7,424 KB
testcase_05 AC 43 ms
7,296 KB
testcase_06 AC 45 ms
7,396 KB
testcase_07 AC 44 ms
7,360 KB
testcase_08 AC 44 ms
7,424 KB
testcase_09 AC 2 ms
5,376 KB
testcase_10 AC 2 ms
5,376 KB
testcase_11 AC 2 ms
5,376 KB
testcase_12 AC 2 ms
5,376 KB
testcase_13 AC 3 ms
5,376 KB
testcase_14 AC 11 ms
5,376 KB
testcase_15 AC 11 ms
5,376 KB
testcase_16 AC 10 ms
5,376 KB
testcase_17 AC 11 ms
5,376 KB
testcase_18 AC 11 ms
5,376 KB
testcase_19 AC 10 ms
5,376 KB
testcase_20 AC 11 ms
5,376 KB
testcase_21 AC 2 ms
5,376 KB
testcase_22 AC 2 ms
5,376 KB
testcase_23 AC 2 ms
5,376 KB
testcase_24 AC 2 ms
5,376 KB
testcase_25 AC 2 ms
5,376 KB
testcase_26 AC 2 ms
5,376 KB
testcase_27 AC 2 ms
5,376 KB
testcase_28 AC 2 ms
5,376 KB
testcase_29 AC 2 ms
5,376 KB
testcase_30 AC 2 ms
5,376 KB
testcase_31 AC 2 ms
5,376 KB
testcase_32 AC 2 ms
5,376 KB
testcase_33 AC 2 ms
5,376 KB
testcase_34 AC 2 ms
5,376 KB
testcase_35 AC 3 ms
5,376 KB
testcase_36 AC 3 ms
5,376 KB
testcase_37 AC 2 ms
5,376 KB
testcase_38 AC 3 ms
5,376 KB
testcase_39 AC 3 ms
5,376 KB
testcase_40 AC 56 ms
9,444 KB
testcase_41 AC 50 ms
9,472 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <tuple>
#include <cmath>
#include <numeric>
#include <functional>
#include <cassert>

#define debug_value(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << #x << "=" << x << endl;
#define debug(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << x << endl;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

using namespace std;
typedef long long ll;

bool ok(string s){
    int m = s.size();
    for(int i = 1; i < m; i++){
        if(s[i] < s[i-1]) return false;
    }
    return true;
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << setprecision(10) << fixed;
    int n; cin >> n;
    vector<int> dp(26);
    vector<string> t(n);
    for(int i = 0; i < n; i++) cin >> t[i];
    sort(t.begin(), t.end());
    for(int i = 0; i < n; i++){
        string s = t[i];
        if(!ok(s)) continue;
        int l = s[0]-'a';
        int r = s.back()-'a';
        int mx = 0;
        for(int j = 0; j < 26; j++){
            if(j <= l) chmax(mx, dp[j]);
        }
        chmax(dp[r], mx+(int)s.size());
    }
    cout << *max_element(dp.begin(), dp.end()) << endl;
}
0