結果

問題 No.437 cwwゲーム
ユーザー bluemeganebluemegane
提出日時 2018-10-10 09:59:28
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 90 ms / 2,000 ms
コード長 2,343 bytes
コンパイル時間 1,010 ms
コンパイル使用メモリ 109,568 KB
実行使用メモリ 24,320 KB
最終ジャッジ日時 2024-04-20 13:21:48
合計ジャッジ時間 3,838 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 32 ms
19,840 KB
testcase_01 AC 24 ms
19,328 KB
testcase_02 AC 35 ms
21,248 KB
testcase_03 AC 32 ms
19,968 KB
testcase_04 AC 32 ms
20,480 KB
testcase_05 AC 36 ms
21,504 KB
testcase_06 AC 44 ms
24,192 KB
testcase_07 AC 80 ms
24,064 KB
testcase_08 AC 58 ms
24,320 KB
testcase_09 AC 80 ms
23,936 KB
testcase_10 AC 75 ms
23,936 KB
testcase_11 AC 32 ms
20,096 KB
testcase_12 AC 41 ms
23,808 KB
testcase_13 AC 38 ms
22,016 KB
testcase_14 AC 36 ms
21,248 KB
testcase_15 AC 90 ms
24,064 KB
testcase_16 AC 34 ms
20,736 KB
testcase_17 AC 35 ms
20,608 KB
testcase_18 AC 35 ms
20,736 KB
testcase_19 AC 33 ms
19,840 KB
testcase_20 AC 32 ms
19,968 KB
testcase_21 AC 33 ms
19,968 KB
testcase_22 AC 34 ms
19,968 KB
testcase_23 AC 34 ms
20,096 KB
testcase_24 AC 33 ms
19,840 KB
testcase_25 AC 34 ms
20,864 KB
testcase_26 AC 35 ms
20,608 KB
testcase_27 AC 32 ms
19,968 KB
testcase_28 AC 32 ms
19,968 KB
testcase_29 AC 33 ms
20,096 KB
testcase_30 AC 24 ms
19,584 KB
testcase_31 AC 33 ms
19,968 KB
testcase_32 AC 24 ms
19,712 KB
testcase_33 AC 34 ms
20,864 KB
testcase_34 AC 33 ms
20,224 KB
testcase_35 AC 33 ms
20,224 KB
testcase_36 AC 24 ms
19,584 KB
testcase_37 AC 24 ms
19,840 KB
testcase_38 AC 33 ms
19,968 KB
testcase_39 AC 24 ms
19,584 KB
testcase_40 AC 34 ms
19,840 KB
testcase_41 AC 36 ms
20,352 KB
testcase_42 AC 35 ms
20,480 KB
testcase_43 AC 34 ms
20,352 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc)
Copyright (C) Microsoft Corporation. All rights reserved.

ソースコード

diff #

using System.Linq;
using System.Collections.Generic;
using System;

public static class combi
{
    public static IEnumerable<IEnumerable<T>> Comb<T>(this IEnumerable<T> items, int r)
    {
        if (r == 0)
        {
            yield return Enumerable.Empty<T>();
        }
        else
        {
            var i = 1;
            foreach (var x in items)
            {
                var xs = items.Skip(i);
                foreach (var c in Comb(xs, r - 1))
                    yield return c.Before(x);
                i++;
            }
        }
    }
    public static IEnumerable<T> Before<T>(this IEnumerable<T> items, T first)
    {
        yield return first;
        foreach (var i in items)
            yield return i;
    }
}

public class P
{
    public int score { get; set; }
    public int[] a { get; set; }
}

public class Hello
{
    public static void Main()
    {
        var s = Console.ReadLine().Trim();
        var sL = s.Length;
        if (sL <= 2) { Console.WriteLine(0); goto end; }
        var a = new int[sL];
        var w = new P { a = new int[sL] };
        for (int i = 0; i < sL; i++) w.a[i] = int.Parse(s[i].ToString());
        var ans = new HashSet<int>();
        rec(w, ans);
        if (ans.Count() == 0) Console.WriteLine(0);
        else Console.WriteLine(ans.Max());
        end:;
    }
    public static void rec(P p, HashSet<int> ans)
    {
        ans.Add(p.score);
        var aL = p.a.Length;
        if (aL <= 2 && p.score != 0) return;
        foreach (var x in Enumerable.Range(0, aL).Comb(3))
        {
            var w = x.ToArray();
            var c = checkCWW(p.a, w);
            if (c > 0)
            {
                ans.Add(c);
                if (aL - 3 >= 1)
                {
                    var w2 = new P { a = new int[aL - 3], score = p.score + c };
                    var pt = 0;
                    for (int i = 0; i < aL; i++)
                        if (!w.Contains(i)) w2.a[pt++] = p.a[i];
                    rec(w2, ans);
                }
                else ans.Add(p.score + c);
            }
        }
    }
    public static int checkCWW(int[] a, int[] b)
    {
        if (a[b[0]] == 0) return -1;
        if (a[b[0]] == a[b[1]]) return -1;
        if (a[b[1]] == a[b[2]]) return 100 * a[b[0]] + 10 * a[b[1]] + a[b[2]];
        return -1;
    }
}
0