結果

問題 No.1512 作文
ユーザー KKT89KKT89
提出日時 2021-05-21 21:26:21
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 63 ms / 2,000 ms
コード長 848 bytes
コンパイル時間 3,452 ms
コンパイル使用メモリ 224,664 KB
実行使用メモリ 12,852 KB
最終ジャッジ日時 2024-04-18 14:26:22
合計ジャッジ時間 5,016 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,816 KB
testcase_01 AC 2 ms
6,940 KB
testcase_02 AC 2 ms
6,940 KB
testcase_03 AC 1 ms
6,944 KB
testcase_04 AC 38 ms
8,296 KB
testcase_05 AC 40 ms
8,428 KB
testcase_06 AC 40 ms
7,912 KB
testcase_07 AC 36 ms
7,780 KB
testcase_08 AC 39 ms
8,936 KB
testcase_09 AC 8 ms
6,940 KB
testcase_10 AC 8 ms
6,940 KB
testcase_11 AC 7 ms
6,944 KB
testcase_12 AC 7 ms
6,944 KB
testcase_13 AC 7 ms
6,940 KB
testcase_14 AC 7 ms
6,944 KB
testcase_15 AC 8 ms
6,944 KB
testcase_16 AC 7 ms
6,944 KB
testcase_17 AC 7 ms
6,944 KB
testcase_18 AC 7 ms
6,944 KB
testcase_19 AC 7 ms
6,940 KB
testcase_20 AC 7 ms
6,940 KB
testcase_21 AC 2 ms
6,940 KB
testcase_22 AC 2 ms
6,944 KB
testcase_23 AC 2 ms
6,944 KB
testcase_24 AC 3 ms
6,944 KB
testcase_25 AC 3 ms
6,944 KB
testcase_26 AC 2 ms
6,944 KB
testcase_27 AC 2 ms
6,940 KB
testcase_28 AC 2 ms
6,940 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 2 ms
6,944 KB
testcase_33 AC 2 ms
6,940 KB
testcase_34 AC 2 ms
6,940 KB
testcase_35 AC 4 ms
6,940 KB
testcase_36 AC 4 ms
6,940 KB
testcase_37 AC 3 ms
6,944 KB
testcase_38 AC 4 ms
6,940 KB
testcase_39 AC 3 ms
6,940 KB
testcase_40 AC 63 ms
12,852 KB
testcase_41 AC 58 ms
12,200 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef unsigned long long ull;

mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
ll myRand(ll B) {
    return (ull)rng() % B;
}

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n; cin >> n;
    vector<string> v;
    vector<int> dp(27);
    for(int i=0;i<n;i++){
        string s,t; cin >> s;
        t=s;
        sort(t.begin(), t.end());
        if(t==s){
            v.push_back(t);
        }
    }
    sort(v.begin(), v.end());
    for(int i=0;i<v.size();i++){
        dp[v[i].back()-'a']=max(dp[v[i].back()-'a'],dp[v[i][0]-'a']+(int)v[i].size());
        for(int j=0;j<26;j++){
            dp[j+1]=max(dp[j+1],dp[j]);
        }
    }
    cout << *max_element(dp.begin(), dp.end()) << endl;
}
0