結果

問題 No.1512 作文
ユーザー ytqm3ytqm3
提出日時 2021-05-22 12:36:03
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 24 ms / 2,000 ms
コード長 1,796 bytes
コンパイル時間 2,045 ms
コンパイル使用メモリ 202,688 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-07-31 17:33:30
合計ジャッジ時間 3,925 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,384 KB
testcase_04 AC 20 ms
4,380 KB
testcase_05 AC 19 ms
4,380 KB
testcase_06 AC 19 ms
4,380 KB
testcase_07 AC 19 ms
4,380 KB
testcase_08 AC 19 ms
4,376 KB
testcase_09 AC 5 ms
4,376 KB
testcase_10 AC 5 ms
4,380 KB
testcase_11 AC 4 ms
4,380 KB
testcase_12 AC 5 ms
4,376 KB
testcase_13 AC 5 ms
4,380 KB
testcase_14 AC 8 ms
4,376 KB
testcase_15 AC 8 ms
4,376 KB
testcase_16 AC 7 ms
4,380 KB
testcase_17 AC 8 ms
4,380 KB
testcase_18 AC 8 ms
4,380 KB
testcase_19 AC 7 ms
4,384 KB
testcase_20 AC 8 ms
4,380 KB
testcase_21 AC 2 ms
4,380 KB
testcase_22 AC 2 ms
4,376 KB
testcase_23 AC 2 ms
4,380 KB
testcase_24 AC 2 ms
4,376 KB
testcase_25 AC 2 ms
4,376 KB
testcase_26 AC 2 ms
4,376 KB
testcase_27 AC 2 ms
4,376 KB
testcase_28 AC 2 ms
4,380 KB
testcase_29 AC 2 ms
4,376 KB
testcase_30 AC 2 ms
4,380 KB
testcase_31 AC 1 ms
4,384 KB
testcase_32 AC 1 ms
4,376 KB
testcase_33 AC 2 ms
4,376 KB
testcase_34 AC 1 ms
4,380 KB
testcase_35 AC 6 ms
4,376 KB
testcase_36 AC 5 ms
4,380 KB
testcase_37 AC 4 ms
4,380 KB
testcase_38 AC 5 ms
4,380 KB
testcase_39 AC 5 ms
4,376 KB
testcase_40 AC 24 ms
4,380 KB
testcase_41 AC 24 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
typedef int64_t i64;
typedef long double f128;
using namespace std;

template<typename T>
void scan(T& n)
{
  cin>>n;
  return;
}

void scan()
{
  return;
}

template<typename T,class... Args>
void scan(T& n,Args&... args)
{
  scan(n);
  scan(args...);
  return;
}

template<typename T>
void scan_array(T start,T end)
{
  T now=start;
  for(;now!=end;++now)
  {
    scan(*now);
  }
  return;
}

template<typename T>
void print(T n)
{
  cout<<n;
  return;
}

template<typename T>
void println(T n)
{
  print(n);
  print('\n');
  return;
}

template<typename T,class... Args>
void println(T n,Args... args)
{
  print(n);
  print(' ');
  println(args...);
  return;
}

template<typename T>
void print_array(T start,T end)
{
  T now=start;
  print(*now);
  for(;now!=end;++now)
  {
    print(' ');
    print(*now);
  }
  print("");
  return;
}

i64 pow_mod(i64 a,i64 n,i64 mod)
{
  i64 res=1,now=a;
  while(n)
  {
    if(n&1)
    {
      res=res*now%mod;
    }
    now=now*now%mod;
    n>>=1;
  }
  return res;
}

i64 inv_mod(i64 a,i64 mod)
{
  return pow_mod(a,mod-2,mod);
}

int main()
{
  int N;
  scan(N);
  vector<vector<int>> G(26,vector<int> (26));
  vector<int> vec(26);
  for(int i=0;i<N;++i)
  {
    string S;
    scan(S);
    char now='a';
    bool is_good=1;
    for(size_t i=0;i<S.size();++i)
    {
      if(S[i]<now)
      {
        is_good=0;
      }
      now=S[i];
    }
    if(!is_good)
    {
      continue;
    }
    if(S[0]==S.back())
    {
      vec[S[0]-'a']+=S.size();
    }
    else
    {
      G[S[0]-'a'][S.back()-'a']=max(G[S[0]-'a'][S.back()-'a'],(int)S.size());
    }
  }
  vector<int> ans(26);
  for(int i=0;i<26;++i)
  {
    for(int j=0;j<i;++j)
    {
      ans[i]=max(ans[i],ans[j]+G[j][i]);
    }
    ans[i]+=vec[i];
  }
  println(ans[25]);
}
0