結果

問題 No.1512 作文
ユーザー akaneakane
提出日時 2021-05-21 22:11:55
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 508 ms / 2,000 ms
コード長 1,258 bytes
コンパイル時間 2,855 ms
コンパイル使用メモリ 206,628 KB
実行使用メモリ 11,620 KB
最終ジャッジ日時 2024-04-18 15:41:23
合計ジャッジ時間 6,498 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
5,248 KB
testcase_01 AC 3 ms
5,376 KB
testcase_02 AC 4 ms
5,376 KB
testcase_03 AC 4 ms
5,376 KB
testcase_04 AC 264 ms
7,524 KB
testcase_05 AC 254 ms
7,520 KB
testcase_06 AC 273 ms
7,652 KB
testcase_07 AC 264 ms
7,524 KB
testcase_08 AC 267 ms
7,524 KB
testcase_09 AC 10 ms
5,376 KB
testcase_10 AC 11 ms
5,376 KB
testcase_11 AC 11 ms
5,376 KB
testcase_12 AC 11 ms
5,376 KB
testcase_13 AC 11 ms
5,376 KB
testcase_14 AC 13 ms
5,376 KB
testcase_15 AC 12 ms
5,376 KB
testcase_16 AC 12 ms
5,376 KB
testcase_17 AC 12 ms
5,376 KB
testcase_18 AC 13 ms
5,376 KB
testcase_19 AC 12 ms
5,376 KB
testcase_20 AC 12 ms
5,376 KB
testcase_21 AC 4 ms
5,376 KB
testcase_22 AC 4 ms
5,376 KB
testcase_23 AC 4 ms
5,376 KB
testcase_24 AC 4 ms
5,376 KB
testcase_25 AC 4 ms
5,376 KB
testcase_26 AC 4 ms
5,376 KB
testcase_27 AC 3 ms
5,376 KB
testcase_28 AC 3 ms
5,376 KB
testcase_29 AC 4 ms
5,376 KB
testcase_30 AC 4 ms
5,376 KB
testcase_31 AC 4 ms
5,376 KB
testcase_32 AC 4 ms
5,376 KB
testcase_33 AC 3 ms
5,376 KB
testcase_34 AC 5 ms
5,376 KB
testcase_35 AC 8 ms
5,376 KB
testcase_36 AC 7 ms
5,376 KB
testcase_37 AC 5 ms
5,376 KB
testcase_38 AC 6 ms
5,376 KB
testcase_39 AC 6 ms
5,376 KB
testcase_40 AC 508 ms
11,620 KB
testcase_41 AC 506 ms
11,616 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#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;
}
0