結果

問題 No.1512 作文
ユーザー Manuel1024Manuel1024
提出日時 2022-01-12 22:55:12
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 71 ms / 2,000 ms
コード長 1,247 bytes
コンパイル時間 731 ms
コンパイル使用メモリ 82,856 KB
実行使用メモリ 38,532 KB
最終ジャッジ日時 2024-04-27 13:22:16
合計ジャッジ時間 2,933 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
6,812 KB
testcase_01 AC 2 ms
6,940 KB
testcase_02 AC 1 ms
6,940 KB
testcase_03 AC 1 ms
6,944 KB
testcase_04 AC 42 ms
22,040 KB
testcase_05 AC 41 ms
21,908 KB
testcase_06 AC 46 ms
22,040 KB
testcase_07 AC 43 ms
22,036 KB
testcase_08 AC 43 ms
22,044 KB
testcase_09 AC 6 ms
6,944 KB
testcase_10 AC 5 ms
6,940 KB
testcase_11 AC 4 ms
6,940 KB
testcase_12 AC 5 ms
6,944 KB
testcase_13 AC 5 ms
6,944 KB
testcase_14 AC 8 ms
6,940 KB
testcase_15 AC 8 ms
6,944 KB
testcase_16 AC 8 ms
6,944 KB
testcase_17 AC 8 ms
6,940 KB
testcase_18 AC 8 ms
6,940 KB
testcase_19 AC 8 ms
6,944 KB
testcase_20 AC 8 ms
6,944 KB
testcase_21 AC 2 ms
6,940 KB
testcase_22 AC 2 ms
6,940 KB
testcase_23 AC 2 ms
6,940 KB
testcase_24 AC 2 ms
6,940 KB
testcase_25 AC 2 ms
6,940 KB
testcase_26 AC 2 ms
6,944 KB
testcase_27 AC 2 ms
6,944 KB
testcase_28 AC 1 ms
6,944 KB
testcase_29 AC 1 ms
6,944 KB
testcase_30 AC 1 ms
6,940 KB
testcase_31 AC 2 ms
6,944 KB
testcase_32 AC 1 ms
6,944 KB
testcase_33 AC 1 ms
6,944 KB
testcase_34 AC 2 ms
6,940 KB
testcase_35 AC 6 ms
6,940 KB
testcase_36 AC 6 ms
6,944 KB
testcase_37 AC 3 ms
6,944 KB
testcase_38 AC 5 ms
6,944 KB
testcase_39 AC 5 ms
6,940 KB
testcase_40 AC 69 ms
38,364 KB
testcase_41 AC 71 ms
38,532 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
using namespace std;

struct tup{
    int s;
    int e;
    int len;
    tup(int s, int e, int len): s(s), e(e), len(len){}
    bool operator<(const tup &other) const {
        if(this->e != other.e) return this->e < other.e;
        else return this->s < other.s;
    };
};

int main(){
    int n;
    cin >> n;
    vector<string> s(n);
    for(auto &p: s) cin >> p;

    vector<tup> t;
    for(auto &it: s){
        bool isgood = true;
        for(int i = 1; i < it.size(); i++){
            if(it[i-1] > it[i]) isgood = false;
        }
        if(isgood) t.emplace_back(it[0]-'a', it.back()-'a', it.size());
    }

    sort(t.begin(), t.end());

    vector<vector<int>> dp(t.size()+1, vector<int>(26, -(1 << 30)));
    for(int i = 0; i < t.size(); i++){
        dp[i][t[i].e] = max(dp[i][t[i].e], t[i].len);
        if(i > 0){
            for(int j = 0; j <= t[i].s; j++) dp[i][t[i].e] = max(dp[i][t[i].e], dp[i-1][j]+t[i].len);
        }
        for(int j = 0; j < 26; j++){
            dp[i+1][j] = max(dp[i+1][j], dp[i][j]);
        }
    }
    int ans = 0;
    for(int i = 0; i < 26; i++) ans = max(ans, dp[t.size()][i]);
    cout << ans << endl;
    return 0;
}
0