結果

問題 No.1512 作文
ユーザー 沙耶花沙耶花
提出日時 2021-05-21 21:24:05
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 808 bytes
コンパイル時間 4,421 ms
コンパイル使用メモリ 269,264 KB
実行使用メモリ 12,920 KB
最終ジャッジ日時 2023-07-31 14:19:09
合計ジャッジ時間 6,488 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 27 ms
8,500 KB
testcase_05 AC 28 ms
8,864 KB
testcase_06 AC 28 ms
8,088 KB
testcase_07 AC 27 ms
8,076 KB
testcase_08 AC 28 ms
7,464 KB
testcase_09 AC 12 ms
4,376 KB
testcase_10 AC 12 ms
4,376 KB
testcase_11 AC 12 ms
4,376 KB
testcase_12 AC 13 ms
4,376 KB
testcase_13 AC 12 ms
4,376 KB
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 AC 11 ms
4,380 KB
testcase_21 AC 2 ms
4,380 KB
testcase_22 AC 2 ms
4,376 KB
testcase_23 AC 3 ms
4,380 KB
testcase_24 WA -
testcase_25 AC 2 ms
4,376 KB
testcase_26 AC 1 ms
4,376 KB
testcase_27 AC 1 ms
4,380 KB
testcase_28 AC 2 ms
4,380 KB
testcase_29 AC 1 ms
4,376 KB
testcase_30 AC 1 ms
4,376 KB
testcase_31 AC 1 ms
4,380 KB
testcase_32 WA -
testcase_33 AC 1 ms
4,380 KB
testcase_34 AC 2 ms
4,380 KB
testcase_35 AC 9 ms
4,376 KB
testcase_36 AC 9 ms
4,376 KB
testcase_37 AC 5 ms
4,376 KB
testcase_38 AC 7 ms
4,376 KB
testcase_39 AC 7 ms
4,380 KB
testcase_40 AC 36 ms
12,920 KB
testcase_41 AC 35 ms
11,352 KB
権限があれば一括ダウンロードができます

ソースコード

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