結果
| 問題 |
No.1512 作文
|
| コンテスト | |
| ユーザー |
akane
|
| 提出日時 | 2021-05-21 22:05:52 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,209 bytes |
| コンパイル時間 | 2,362 ms |
| コンパイル使用メモリ | 205,600 KB |
| 最終ジャッジ日時 | 2025-01-21 15:22:48 |
|
ジャッジサーバーID (参考情報) |
judge1 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 21 WA * 17 |
ソースコード
#include <bits/stdc++.h>
#define rep(i,n) for (int i=0; i < (n); i++)
using namespace std;
using ll = long long;
int ctoi(char x){
return x - 'a';
}
int main(){
ios::sync_with_stdio(false);
int N; cin>>N;
vector<string> pos;
rep(i,N){
string s; cin>>s;
string t=s;
sort(s.begin(), s.end());
if(s==t) pos.push_back(s);
}
// for(string x:pos){
// cerr << x << endl;
// }
vector<vector<int>> moji(26,vector<int>(26,0));
for(string x:pos){
int l=ctoi(x[0]), r=ctoi(x[x.size()-1]);
int len=x.size();
moji[l][r]=max(moji[l][r], len);
}
rep(i,26){
rep(j,26){
cerr << moji[i][j] << " ";
}cerr << endl;
}
cerr << "-------------------" << endl;
int ans=0;
vector<int> dp(26,0);
for(int r=0; r<26; r++){
for(int l=0; l<=r; l++){
if(r==0) dp[r] = max(dp[r],moji[r][r]);
if(r>0){
dp[r] = max(dp[r], dp[l]+moji[l][r]);
}
}
// dp[r] += moji[r][r];
ans = max(ans,dp[r]);
}
rep(i,26){
cerr << dp[i] << " ";
}cerr << endl;
cout << ans << endl;
}
akane