結果

問題 No.1512 作文
ユーザー kotatsugame
提出日時 2021-05-21 21:24:24
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 23 ms / 2,000 ms
コード長 578 bytes
コンパイル時間 752 ms
コンパイル使用メモリ 68,276 KB
実行使用メモリ 5,248 KB
最終ジャッジ日時 2024-10-10 07:38:03
合計ジャッジ時間 2,338 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 38
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp:7:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
    7 | main()
      | ^~~~

ソースコード

diff #

#include<iostream>
#include<algorithm>
using namespace std;
int N;
int dist[26][26];
int dp[26];
main()
{
	cin>>N;
	for(int i=0;i<N;i++)
	{
		string s;cin>>s;
		int fst=s[0]-'a';
		int lst=fst;
		for(int j=1;j<s.size();j++)
		{
			if(lst<s[j]-'a')lst=s[j]-'a';
			else if(lst>s[j]-'a')
			{
				lst=-1;
				break;
			}
		}
		if(lst>=0)
		{
			if(fst<lst)dist[fst][lst]=max(dist[fst][lst],(int)s.size());
			else dist[fst][lst]+=s.size();
		}
	}
	for(int i=0;i<26;i++)
	{
		dp[i]+=dist[i][i];
		for(int j=i+1;j<26;j++)dp[j]=max(dp[j],dp[i]+dist[i][j]);
	}
	cout<<dp[25]<<endl;
}
0