結果

問題 No.1512 作文
ユーザー srjywrdnprktsrjywrdnprkt
提出日時 2023-06-18 21:30:47
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 42 ms / 2,000 ms
コード長 787 bytes
コンパイル時間 2,229 ms
コンパイル使用メモリ 211,764 KB
実行使用メモリ 6,288 KB
最終ジャッジ日時 2023-09-08 15:54:56
合計ジャッジ時間 5,866 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 31 ms
4,688 KB
testcase_05 AC 30 ms
4,852 KB
testcase_06 AC 30 ms
4,688 KB
testcase_07 AC 30 ms
4,712 KB
testcase_08 AC 31 ms
4,692 KB
testcase_09 AC 5 ms
4,376 KB
testcase_10 AC 5 ms
4,380 KB
testcase_11 AC 5 ms
4,376 KB
testcase_12 AC 5 ms
4,376 KB
testcase_13 AC 5 ms
4,376 KB
testcase_14 AC 8 ms
4,376 KB
testcase_15 AC 7 ms
4,380 KB
testcase_16 AC 7 ms
4,380 KB
testcase_17 AC 8 ms
4,376 KB
testcase_18 AC 7 ms
4,376 KB
testcase_19 AC 7 ms
4,376 KB
testcase_20 AC 8 ms
4,376 KB
testcase_21 AC 2 ms
4,380 KB
testcase_22 AC 2 ms
4,380 KB
testcase_23 AC 2 ms
4,380 KB
testcase_24 AC 2 ms
4,376 KB
testcase_25 AC 2 ms
4,380 KB
testcase_26 AC 1 ms
4,380 KB
testcase_27 AC 2 ms
4,376 KB
testcase_28 AC 1 ms
4,380 KB
testcase_29 AC 1 ms
4,380 KB
testcase_30 AC 2 ms
4,380 KB
testcase_31 AC 2 ms
4,380 KB
testcase_32 AC 1 ms
4,380 KB
testcase_33 AC 1 ms
4,380 KB
testcase_34 AC 2 ms
4,376 KB
testcase_35 AC 6 ms
4,376 KB
testcase_36 AC 5 ms
4,376 KB
testcase_37 AC 3 ms
4,376 KB
testcase_38 AC 5 ms
4,376 KB
testcase_39 AC 5 ms
4,376 KB
testcase_40 AC 42 ms
6,288 KB
testcase_41 AC 38 ms
6,180 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;
using ll = long long;

bool check(string &s){
    int N=s.size();
    for (int i=0; i<N-1; i++) if (s[i] > s[i+1]) return 0;
    return 1;
}

int main(){

    int N, a, b, c, ans=0;
    cin >> N;
    string T;
    vector<tuple<int, int, int>> S;
    for (int i=0; i<N; i++){
        cin >> T;
        if (check(T)){
            S.push_back({T.back()-'a', T[0]-'a', (int)T.size()});
        }
    }

    N = S.size();
    sort(S.begin(), S.end());
    vector<int> dp(26);
    for (int i=0; i<N; i++){
        tie(b, a, c) = S[i];
        ans = 0;
        for (int j=0; j<=a; j++) ans = max(ans, dp[j]);
        dp[b] = max({dp[b], ans+c});
    }

    for (int i=0; i<26; i++) ans = max(ans, dp[i]);
    cout << ans << endl;

    return 0;
}
0