結果

問題 No.1512 作文
ユーザー TomorrowNextTomorrowNext
提出日時 2021-05-21 21:38:48
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,409 bytes
コンパイル時間 1,810 ms
コンパイル使用メモリ 173,180 KB
実行使用メモリ 18,024 KB
最終ジャッジ日時 2024-04-18 14:54:38
合計ジャッジ時間 3,239 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,816 KB
testcase_01 AC 1 ms
6,940 KB
testcase_02 AC 2 ms
6,944 KB
testcase_03 AC 2 ms
6,944 KB
testcase_04 AC 26 ms
10,596 KB
testcase_05 AC 25 ms
10,596 KB
testcase_06 AC 25 ms
10,852 KB
testcase_07 AC 24 ms
10,724 KB
testcase_08 AC 25 ms
10,724 KB
testcase_09 AC 2 ms
6,940 KB
testcase_10 AC 3 ms
6,944 KB
testcase_11 AC 2 ms
6,944 KB
testcase_12 AC 2 ms
6,940 KB
testcase_13 AC 2 ms
6,940 KB
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 AC 2 ms
6,944 KB
testcase_22 AC 2 ms
6,944 KB
testcase_23 AC 2 ms
6,944 KB
testcase_24 AC 2 ms
6,940 KB
testcase_25 AC 2 ms
6,944 KB
testcase_26 AC 1 ms
6,940 KB
testcase_27 AC 2 ms
6,940 KB
testcase_28 AC 2 ms
6,944 KB
testcase_29 AC 2 ms
6,940 KB
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
testcase_35 AC 3 ms
6,944 KB
testcase_36 AC 2 ms
6,944 KB
testcase_37 AC 2 ms
6,944 KB
testcase_38 AC 2 ms
6,944 KB
testcase_39 AC 2 ms
6,944 KB
testcase_40 AC 38 ms
18,016 KB
testcase_41 AC 33 ms
18,024 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include "bits/stdc++.h"

using namespace std;
using ll = long long;

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

int dp(int curr, char last, const vector<pair<pair<char, char>, int>>& S, vector<int>& memo) {
    if (curr == S.size()) {
        return 0;
    }
    if (memo[curr] >= 0) {
        return memo[curr];
    }

    int ret = 0;
    if (last <= S[curr].first.first) {
        int take = dp(curr + 1, S[curr].first.second, S, memo) + S[curr].second;
        int skip = dp(curr + 1, last, S, memo);
        ret = max(take, skip);
    }
    else {
        ret = dp(curr + 1, last, S, memo);
    }
    memo[curr] = ret;
    return ret;
}

void Main() {
    int N;
    cin >> N;
    vector<pair<pair<char, char>, int>> S;
    for (int i = 0; i < N; ++i) {
        string s;
        cin >> s;
        if (isGood(s)) {
            S.push_back(make_pair(make_pair(s[0], s[s.size() - 1]), s.size()));
        }
    }
    sort(S.begin(), S.end());

    if (S.size() == 0) {
        cout << 0 << endl;
        return;
    }
    vector<int> memo(S.size() + 10, -1);
    int ans = dp(0, 'a', S, memo);
    cout << ans << endl;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    std::cout << std::fixed << std::setprecision(15);
    Main();
    return 0;
}
0