結果

問題 No.1512 作文
ユーザー se1ka2se1ka2
提出日時 2021-05-21 21:33:41
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 46 ms / 2,000 ms
コード長 838 bytes
コンパイル時間 869 ms
コンパイル使用メモリ 74,396 KB
実行使用メモリ 12,172 KB
最終ジャッジ日時 2023-07-31 14:41:43
合計ジャッジ時間 2,914 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
9,860 KB
testcase_01 AC 4 ms
9,808 KB
testcase_02 AC 4 ms
10,108 KB
testcase_03 AC 4 ms
9,812 KB
testcase_04 AC 34 ms
11,416 KB
testcase_05 AC 35 ms
11,428 KB
testcase_06 AC 35 ms
11,420 KB
testcase_07 AC 35 ms
11,356 KB
testcase_08 AC 36 ms
11,424 KB
testcase_09 AC 7 ms
10,280 KB
testcase_10 AC 8 ms
10,320 KB
testcase_11 AC 7 ms
10,192 KB
testcase_12 AC 7 ms
10,376 KB
testcase_13 AC 7 ms
9,976 KB
testcase_14 AC 12 ms
10,584 KB
testcase_15 AC 12 ms
10,312 KB
testcase_16 AC 12 ms
10,376 KB
testcase_17 AC 12 ms
10,240 KB
testcase_18 AC 12 ms
10,552 KB
testcase_19 AC 11 ms
10,312 KB
testcase_20 AC 11 ms
10,316 KB
testcase_21 AC 4 ms
9,956 KB
testcase_22 AC 4 ms
9,876 KB
testcase_23 AC 4 ms
9,984 KB
testcase_24 AC 4 ms
10,144 KB
testcase_25 AC 4 ms
9,960 KB
testcase_26 AC 4 ms
10,024 KB
testcase_27 AC 4 ms
9,880 KB
testcase_28 AC 4 ms
9,808 KB
testcase_29 AC 4 ms
9,872 KB
testcase_30 AC 4 ms
9,860 KB
testcase_31 AC 4 ms
9,936 KB
testcase_32 AC 4 ms
9,888 KB
testcase_33 AC 4 ms
9,804 KB
testcase_34 AC 4 ms
9,908 KB
testcase_35 AC 8 ms
10,124 KB
testcase_36 AC 8 ms
9,980 KB
testcase_37 AC 6 ms
9,988 KB
testcase_38 AC 8 ms
10,176 KB
testcase_39 AC 8 ms
10,448 KB
testcase_40 AC 46 ms
12,172 KB
testcase_41 AC 41 ms
11,956 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <algorithm>
#include <iostream>
using namespace std;
typedef pair<int, int> P;
typedef pair<P, int> PP;

string s[200005];
PP p[200005];

int main()
{
    int n;
    cin >> n;
    for(int i = 0; i < n; i++) cin >> s[i];
    for(int i = 0; i < n; i++){
        bool f = true;
        int k = s[i].size();
        for(int j = 0; j < k - 1; j++){
            if(s[i][j] > s[i][j + 1]) f = false;
        }
        if(f) p[i] = PP(P(s[i][k - 1] - 'a', s[i][0] - 'a'), k);
        else p[i] = PP(P(-1, -1), k);
    }
    sort(p, p + n);
    int dp[30]{0};
    for(int i = 0; i < n; i++){
        int r = p[i].first.first, l = p[i].first.second, c = p[i].second;
        if(r == -1) continue;
        dp[r] = max(dp[r], dp[l] + c);
        for(int j = 1; j < 26; j++) dp[j] = max(dp[j], dp[j - 1]);
    }
    cout << dp[25] << endl;
}
0