結果
| 問題 | 
                            No.1512 作文
                             | 
                    
| コンテスト | |
| ユーザー | 
                             | 
                    
| 提出日時 | 2021-05-21 22:03:24 | 
| 言語 | C++14  (gcc 13.3.0 + boost 1.87.0)  | 
                    
| 結果 | 
                             
                                WA
                                 
                             
                            
                         | 
                    
| 実行時間 | - | 
| コード長 | 730 bytes | 
| コンパイル時間 | 1,759 ms | 
| コンパイル使用メモリ | 176,908 KB | 
| 実行使用メモリ | 58,044 KB | 
| 最終ジャッジ日時 | 2024-10-10 08:44:17 | 
| 合計ジャッジ時間 | 3,864 ms | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge5 / judge4 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| 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;
using P = pair<int, int>;
int main() {
    int n;
    cin >> n;
    vector<string> s(n);
    rep(i, n) cin >> s[i];
    vector<vector<ll>> dp(n + 1, vector<ll>(26));
    rep(i, n) {
        rep(j, 26) dp[i + 1][j] = dp[i][j];
        string t = s[i];
        sort(t.begin(), t.end());
        if (s[i] != t) continue;
        int m = s[i].size();
        int next = *(s[i].rbegin()) - 'a';
        for (int j = 0; j <= (s[i][0] - 'a'); j++) {
            dp[i + 1][next] = max(dp[i + 1][next], dp[i][j] + m);
        }
    }
    ll ans = 0;
    rep(i, 26) ans = max(ans, dp[n][i]);
    cout << ans << endl;
}