結果
問題 | No.1512 作文 |
ユーザー |
![]() |
提出日時 | 2021-05-21 22:11:55 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 559 ms / 2,000 ms |
コード長 | 1,258 bytes |
コンパイル時間 | 2,241 ms |
コンパイル使用メモリ | 205,172 KB |
最終ジャッジ日時 | 2025-01-21 15:28:57 |
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 38 |
ソースコード
#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(); if(l!=r) moji[l][r]=max(moji[l][r], len); else 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==l) dp[r] = max(dp[r],moji[r][r]); if(r>0 && r!=l){ dp[r] = max(dp[r], dp[l]+moji[l][r]+moji[r][r]); } } // dp[r] += moji[r][r]; ans = max(ans,dp[r]); } rep(i,26){ cerr << dp[i] << " "; }cerr << endl; cout << ans << endl; }