結果

問題 No.1512 作文
ユーザー bluemeganebluemegane
提出日時 2021-11-04 16:55:24
言語 C#(csc)
(csc 3.9.0)
結果
WA  
実行時間 -
コード長 2,023 bytes
コンパイル時間 2,543 ms
コンパイル使用メモリ 108,416 KB
実行使用メモリ 58,240 KB
最終ジャッジ日時 2024-04-22 16:31:24
合計ジャッジ時間 6,324 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 30 ms
18,944 KB
testcase_01 AC 31 ms
18,816 KB
testcase_02 AC 31 ms
18,816 KB
testcase_03 AC 30 ms
19,072 KB
testcase_04 AC 210 ms
40,960 KB
testcase_05 AC 209 ms
40,832 KB
testcase_06 AC 219 ms
40,576 KB
testcase_07 AC 218 ms
41,216 KB
testcase_08 AC 216 ms
40,960 KB
testcase_09 AC 51 ms
19,968 KB
testcase_10 AC 52 ms
19,968 KB
testcase_11 AC 50 ms
20,096 KB
testcase_12 AC 51 ms
19,968 KB
testcase_13 AC 51 ms
19,968 KB
testcase_14 AC 51 ms
23,140 KB
testcase_15 AC 51 ms
23,012 KB
testcase_16 AC 52 ms
23,020 KB
testcase_17 AC 51 ms
23,016 KB
testcase_18 AC 55 ms
23,244 KB
testcase_19 AC 54 ms
23,400 KB
testcase_20 AC 52 ms
23,004 KB
testcase_21 AC 27 ms
18,688 KB
testcase_22 AC 30 ms
18,944 KB
testcase_23 AC 33 ms
19,200 KB
testcase_24 AC 31 ms
19,200 KB
testcase_25 AC 31 ms
19,072 KB
testcase_26 AC 29 ms
18,816 KB
testcase_27 AC 25 ms
18,560 KB
testcase_28 AC 30 ms
18,944 KB
testcase_29 AC 28 ms
18,944 KB
testcase_30 AC 29 ms
19,072 KB
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
testcase_35 AC 56 ms
19,840 KB
testcase_36 AC 55 ms
19,968 KB
testcase_37 AC 43 ms
19,328 KB
testcase_38 AC 50 ms
20,488 KB
testcase_39 AC 50 ms
20,352 KB
testcase_40 AC 381 ms
58,112 KB
testcase_41 AC 251 ms
58,240 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc)
Copyright (C) Microsoft Corporation. All rights reserved.

ソースコード

diff #

using static System.Math;
using System.Collections.Generic;
using System.Linq;
using System;

public class P
{
    public int start { get; set; }
    public int end { get; set; }
    public int L { get; set; }
}

public class Hello
{
    static void Main()
    {
        var n = int.Parse(Console.ReadLine().Trim());
        var ps = new List<P>();
        for (int i = 0; i < n; i++)
        {
            var s = Console.ReadLine().Trim();
            var w = getP(s);
            if (w.start != -1) ps.Add(w);
        }
        getAns(ps);
    }
    static void getAns(List<P> ps)
    {
        var n = ps.Count();
        if (n == 0) { Console.WriteLine(0); return; }
        ps = ps.OrderBy(x => x.end).ThenBy(x => x.start).ToList();
        var dp = new int[n, 27];
        for (int i = 0; i < n; i++)
            for (int j = 1; j <= 26; j++) dp[i, j] = -1;
        var w = ps[0];
        dp[0, 0] = 0;
        dp[0, w.end] = w.L;
        for (int i = 0; i < n - 1; i++)
            for (int j = 1; j <= 26; j++)
            {
                var ww = dp[i, j];
                if (ww != -1)
                {
                    if (ps[i + 1].start < j) goto notselect;
                    var nextend = ps[i + 1].end;
                    var dpp = dp[i + 1, nextend];
                    dp[i + 1, nextend] = dpp == -1 ? ww + ps[i + 1].L : Max(dpp, ww + ps[i + 1].L);
                notselect:;
                    var dpp2 = dp[i + 1, j];
                    dp[i + 1, j] = dpp2 == -1 ? ww : Max(dpp2, ww);
                }
            }
        var ans = 0;
        for (int i = 1; i <= 26; i++)
        {
            if (dp[n - 1, i] != -1) ans = Max(ans, dp[n - 1, i]);
        }
        Console.WriteLine(ans);
    }
    static P getP(string s)
    {
        var sL = s.Length;
        var ss = s.ToCharArray();
        Array.Sort(ss);
        if (new string(ss) == s)
            return new P { start = s[0] - 'a' + 1, end = s[sL - 1] - 'a' + 1, L = sL };
        else return new P { start = -1 };
    }
}
0