結果

問題 No.1512 作文
ユーザー ytftytft
提出日時 2021-08-13 17:03:29
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 744 bytes
コンパイル時間 2,053 ms
コンパイル使用メモリ 169,244 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-04-14 10:27:34
合計ジャッジ時間 5,383 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,812 KB
testcase_01 AC 2 ms
6,944 KB
testcase_02 AC 1 ms
6,940 KB
testcase_03 WA -
testcase_04 RE -
testcase_05 RE -
testcase_06 RE -
testcase_07 RE -
testcase_08 RE -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 RE -
testcase_15 RE -
testcase_16 RE -
testcase_17 RE -
testcase_18 RE -
testcase_19 RE -
testcase_20 RE -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 AC 2 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,944 KB
testcase_30 AC 2 ms
6,940 KB
testcase_31 AC 2 ms
6,940 KB
testcase_32 AC 2 ms
6,944 KB
testcase_33 AC 2 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 4 ms
6,944 KB
testcase_38 AC 6 ms
6,944 KB
testcase_39 WA -
testcase_40 AC 22 ms
6,940 KB
testcase_41 AC 22 ms
6,940 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;



int main(){
    int N;
    cin>>N;
    vector<vector<int>> memo(26,vector<int>(26));
    for(int i=0;i<N;i++){
        string s;
        cin>>s;
        for(int j=1;j<s.size();j++){
            if(s[i-1]>s[i]){
                goto end;
            }
        }
        if(s[0]==s[s.size()-1]){
            memo[s[0]-'a'][s[s.size()-1]-'a']+=s.size();
        }else{
            memo[s[0]-'a'][s[s.size()-1]-'a']=max(memo[s[0]-'a'][s[s.size()-1]-'a'],(int)(s.size()));
        }
        end:{}
    }
    vector<int> dp(26);
    for(int i=0;i<26;i++){
        for(int j=0;j<i;j++){
            dp[i]=max(dp[i],dp[j]+memo[j][i]);
        }
        dp[i]+=memo[i][i];
    }
    cout<<dp[25]<<endl;
}
0