結果

問題 No.1512 作文
ユーザー Y68170842Y68170842
提出日時 2021-05-21 21:52:20
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 68 ms / 2,000 ms
コード長 1,528 bytes
コンパイル時間 2,288 ms
コンパイル使用メモリ 182,848 KB
実行使用メモリ 12,892 KB
最終ジャッジ日時 2024-04-18 15:07:59
合計ジャッジ時間 3,830 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,812 KB
testcase_01 AC 2 ms
6,944 KB
testcase_02 AC 1 ms
6,944 KB
testcase_03 AC 2 ms
6,940 KB
testcase_04 AC 42 ms
9,168 KB
testcase_05 AC 42 ms
7,628 KB
testcase_06 AC 44 ms
9,164 KB
testcase_07 AC 44 ms
8,012 KB
testcase_08 AC 42 ms
9,424 KB
testcase_09 AC 11 ms
6,940 KB
testcase_10 AC 11 ms
6,940 KB
testcase_11 AC 10 ms
6,940 KB
testcase_12 AC 11 ms
6,940 KB
testcase_13 AC 10 ms
6,940 KB
testcase_14 AC 11 ms
6,940 KB
testcase_15 AC 10 ms
6,944 KB
testcase_16 AC 10 ms
6,940 KB
testcase_17 AC 10 ms
6,944 KB
testcase_18 AC 11 ms
6,944 KB
testcase_19 AC 10 ms
6,940 KB
testcase_20 AC 9 ms
6,940 KB
testcase_21 AC 2 ms
6,944 KB
testcase_22 AC 2 ms
6,944 KB
testcase_23 AC 3 ms
6,940 KB
testcase_24 AC 3 ms
6,944 KB
testcase_25 AC 2 ms
6,944 KB
testcase_26 AC 1 ms
6,940 KB
testcase_27 AC 1 ms
6,944 KB
testcase_28 AC 1 ms
6,944 KB
testcase_29 AC 2 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 2 ms
6,940 KB
testcase_34 AC 2 ms
6,940 KB
testcase_35 AC 8 ms
6,944 KB
testcase_36 AC 8 ms
6,940 KB
testcase_37 AC 5 ms
6,940 KB
testcase_38 AC 7 ms
6,944 KB
testcase_39 AC 6 ms
6,944 KB
testcase_40 AC 68 ms
12,024 KB
testcase_41 AC 66 ms
12,892 KB
権限があれば一括ダウンロードができます

ソースコード

diff #








#include <bits/stdc++.h>
// #include <atcoder/all>
// using namespace atcoder;
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define rrep(i,n) for(int i=int(n-1);i>=int(0);--i)
#define fore(i,a) for(auto &i:a)
#define all(x) x.begin(),x.end() 
#define sz(x) ((int)(x).size())
#define bp(x) (__builtin_popcount((long long)(x)))
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define V vector
#define P pair<int,int>
#define TP tuple<int,int,int>
#define F first
#define S second
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
using ll = long long;
using ld = long double;
using namespace std;
const int INF = 1001001001;
const ll INFL = 1001001001001001001;
const int MAX = 200005;

int main() {
    int n;cin>>n;
    V<string> x;
    rep(i,n){
        string s,t;cin>>s;
        t=s;
        sort(all(t));
        if(s==t){
            x.pb(s);
        }
    }
    sort(all(x));
    V<V<ll>> dp(2,V<ll>(30));
    int now=0;
    rep(i,sz(x)){
        now=1-now;
        int m=x[i].back()-'a';
        dp[now]=dp[!now];
        rep(j,x[i].front()-'a'+1){
            chmax(dp[now][m],dp[!now][j]+sz(x[i]));
        }
    }

    ll ans=0;
    rep(i,30){
        chmax(ans,dp[now][i]);
    }

    cout<<ans<<endl;
    return 0;

}


0