結果

問題 No.1512 作文
ユーザー ktr216ktr216
提出日時 2021-05-21 21:56:32
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 128 ms / 2,000 ms
コード長 1,062 bytes
コンパイル時間 2,129 ms
コンパイル使用メモリ 176,020 KB
実行使用メモリ 41,084 KB
最終ジャッジ日時 2024-04-18 15:17:52
合計ジャッジ時間 3,995 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 1 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 67 ms
22,348 KB
testcase_05 AC 67 ms
22,384 KB
testcase_06 AC 66 ms
22,348 KB
testcase_07 AC 68 ms
22,344 KB
testcase_08 AC 67 ms
22,600 KB
testcase_09 AC 5 ms
5,376 KB
testcase_10 AC 6 ms
5,376 KB
testcase_11 AC 5 ms
5,376 KB
testcase_12 AC 6 ms
5,376 KB
testcase_13 AC 6 ms
5,376 KB
testcase_14 AC 8 ms
5,376 KB
testcase_15 AC 8 ms
5,376 KB
testcase_16 AC 8 ms
5,376 KB
testcase_17 AC 8 ms
5,376 KB
testcase_18 AC 8 ms
5,376 KB
testcase_19 AC 8 ms
5,376 KB
testcase_20 AC 8 ms
5,376 KB
testcase_21 AC 2 ms
5,376 KB
testcase_22 AC 2 ms
5,376 KB
testcase_23 AC 3 ms
5,376 KB
testcase_24 AC 3 ms
5,376 KB
testcase_25 AC 3 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 6 ms
5,376 KB
testcase_36 AC 6 ms
5,376 KB
testcase_37 AC 4 ms
5,376 KB
testcase_38 AC 5 ms
5,376 KB
testcase_39 AC 6 ms
5,376 KB
testcase_40 AC 128 ms
40,908 KB
testcase_41 AC 101 ms
41,084 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;

typedef long long ll;

int main() {
    int N;
    scanf("%d", &N);
    string S;
    vector<vector<int>> ESL;
    rep(i, N) {
        cin >> S;
        int l = S.size();
        bool f = false;
        rep(j, l - 1) {
            if (S[j] > S[j + 1]) f = true;
        }
        if (f) continue;
        ESL.push_back({S[l - 1] - 'a', S[0] - 'a', l});
        //cout << S[l - 1] << " " << S[0] << " " << l << endl;
    }
    sort(ESL.begin(), ESL.end());
    int M = ESL.size();
    vector<vector<int>> dp(M + 1, vector<int>(26, 0));
    rep(i, M) {
        rep(j, 26) {
            dp[i + 1][j] = max(dp[i + 1][j], dp[i][j]);
            if (j <= ESL[i][1]) dp[i + 1][ESL[i][0]] = max(dp[i + 1][ESL[i][0]], dp[i][j] + ESL[i][2]);
        }
    }
    int ans = 0;
    rep(i, 26) ans = max(ans, dp[M][i]);
    printf("%d\n", ans);
    /*
    rep(i, M + 1) {
        rep(j, 26) {
            cout << dp[i][j] << " ";
        }
        cout << endl;
    }
    */
}
0