結果

問題 No.1512 作文
ユーザー umezoumezo
提出日時 2021-05-21 22:42:54
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 26 ms / 2,000 ms
コード長 775 bytes
コンパイル時間 2,003 ms
コンパイル使用メモリ 198,360 KB
実行使用メモリ 9,472 KB
最終ジャッジ日時 2024-04-18 16:09:25
合計ジャッジ時間 3,454 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,248 KB
testcase_02 AC 1 ms
5,248 KB
testcase_03 AC 1 ms
5,376 KB
testcase_04 AC 20 ms
7,552 KB
testcase_05 AC 21 ms
7,552 KB
testcase_06 AC 20 ms
7,336 KB
testcase_07 AC 20 ms
7,424 KB
testcase_08 AC 21 ms
7,484 KB
testcase_09 AC 5 ms
5,376 KB
testcase_10 AC 6 ms
5,376 KB
testcase_11 AC 5 ms
5,376 KB
testcase_12 AC 5 ms
5,376 KB
testcase_13 AC 5 ms
5,376 KB
testcase_14 AC 9 ms
5,376 KB
testcase_15 AC 9 ms
5,376 KB
testcase_16 AC 8 ms
5,376 KB
testcase_17 AC 9 ms
5,376 KB
testcase_18 AC 9 ms
5,376 KB
testcase_19 AC 8 ms
5,376 KB
testcase_20 AC 9 ms
5,376 KB
testcase_21 AC 2 ms
5,376 KB
testcase_22 AC 2 ms
5,376 KB
testcase_23 AC 2 ms
5,376 KB
testcase_24 AC 2 ms
5,376 KB
testcase_25 AC 2 ms
5,376 KB
testcase_26 AC 1 ms
5,376 KB
testcase_27 AC 1 ms
5,376 KB
testcase_28 AC 1 ms
5,376 KB
testcase_29 AC 2 ms
5,376 KB
testcase_30 AC 2 ms
5,376 KB
testcase_31 AC 2 ms
5,376 KB
testcase_32 AC 2 ms
5,376 KB
testcase_33 AC 1 ms
5,376 KB
testcase_34 AC 2 ms
5,376 KB
testcase_35 AC 5 ms
5,376 KB
testcase_36 AC 6 ms
5,376 KB
testcase_37 AC 4 ms
5,376 KB
testcase_38 AC 6 ms
5,376 KB
testcase_39 AC 5 ms
5,376 KB
testcase_40 AC 25 ms
9,472 KB
testcase_41 AC 26 ms
9,472 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[i][0]==S[i][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