結果

問題 No.1512 作文
ユーザー umezoumezo
提出日時 2021-05-21 22:40:22
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 769 bytes
コンパイル時間 2,261 ms
コンパイル使用メモリ 198,316 KB
実行使用メモリ 9,600 KB
最終ジャッジ日時 2024-04-18 16:09:00
合計ジャッジ時間 4,115 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ALL(v) v.begin(), v.end()
typedef long long ll;

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

int dp[26];
int G[26][26];

int main(){
  int n;
  cin>>n;
  vector<string> S(n);
  rep(i,n) cin>>S[i];
  
  rep(i,n){
    bool b=true;
    int m=S[i].size();
    rep(j,m-1){
      if(S[i][j]>S[i][j+1]) b=false;
    }
    if(b==false) continue;
    if(S[0]==S[m-1]) G[S[i][0]-'a'][S[i][m-1]-'a']+=m;
    else G[S[i][0]-'a'][S[i][m-1]-'a']=max(G[S[i][0]-'a'][S[i][m-1]-'a'],m);
  }
  
  dp[0]=G[0][0];
  for(int i=1;i<26;i++){
    int tmp=0;
    for(int j=0;j<i;j++){
      tmp=max(tmp,dp[j]+G[j][i]);
    }
    dp[i]=tmp+G[i][i];
  }
  int ans=0;
  rep(i,26) ans=max(ans,dp[i]);
  cout<<ans<<endl;

  return 0;
}
0