結果

問題 No.1512 作文
ユーザー KKT89KKT89
提出日時 2021-05-21 21:26:21
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 60 ms / 2,000 ms
コード長 848 bytes
コンパイル時間 2,935 ms
コンパイル使用メモリ 228,584 KB
最終ジャッジ日時 2025-01-21 14:16:37
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 38
権限があれば一括ダウンロードができます

ソースコード

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