結果

問題 No.1512 作文
ユーザー 沙耶花
提出日時 2021-05-21 21:24:05
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 808 bytes
コンパイル時間 4,294 ms
コンパイル使用メモリ 260,308 KB
最終ジャッジ日時 2025-01-21 14:13:27
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 30 WA * 8
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <stdio.h>
#include <bits/stdc++.h>
#include <atcoder/all>
using namespace atcoder;
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define Inf 1000000001

int main(){
	
	int N;
	cin>>N;
	
	vector<string> S;
	
	rep(i,N){
		string s;
		cin>>s;
		
		string t(s.rbegin(),s.rend());
		sort(t.begin(),t.end());
		if(s!=t)continue;
		S.push_back(s);
	}
	
	vector<vector<pair<int,int>>> X(26);
	
	int ans = 0;
	
	rep(i,S.size()){
		if(S[i][0]==S[i].back())ans += S[i].size();
		else{
			X[S[i][0]-'a'].emplace_back(S[i].back()-'a',S[i].size());
		}
	}
	
	vector dp(26,0);
	
	rep(i,26){
		rep(j,X[i].size()){
			int x = X[i][j].first,y = X[i][j].second;
			dp[x] = max(dp[x],dp[i]+y);
		}
		if(i!=25)dp[i+1] = max(dp[i+1],dp[i]);
	}
	ans += dp.back();
	
	cout<<ans<<endl;
	
	
	return 0;
}
0