結果

問題 No.437 cwwゲーム
ユーザー bluemeganebluemegane
提出日時 2018-10-10 09:51:46
言語 C#(csc)
(csc 3.9.0)
結果
WA  
実行時間 -
コード長 2,339 bytes
コンパイル時間 849 ms
コンパイル使用メモリ 118,168 KB
実行使用メモリ 32,228 KB
最終ジャッジ日時 2024-04-20 19:23:38
合計ジャッジ時間 3,344 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 32 ms
19,840 KB
testcase_01 AC 23 ms
19,584 KB
testcase_02 AC 32 ms
21,376 KB
testcase_03 AC 29 ms
19,712 KB
testcase_04 AC 30 ms
19,968 KB
testcase_05 WA -
testcase_06 WA -
testcase_07 AC 71 ms
24,064 KB
testcase_08 AC 50 ms
24,320 KB
testcase_09 AC 68 ms
24,064 KB
testcase_10 AC 64 ms
24,320 KB
testcase_11 AC 28 ms
20,096 KB
testcase_12 AC 36 ms
23,936 KB
testcase_13 AC 33 ms
22,144 KB
testcase_14 AC 33 ms
21,376 KB
testcase_15 AC 76 ms
24,064 KB
testcase_16 WA -
testcase_17 WA -
testcase_18 AC 32 ms
20,992 KB
testcase_19 AC 32 ms
20,352 KB
testcase_20 AC 29 ms
20,224 KB
testcase_21 AC 29 ms
20,224 KB
testcase_22 AC 31 ms
19,840 KB
testcase_23 WA -
testcase_24 AC 29 ms
20,096 KB
testcase_25 WA -
testcase_26 AC 33 ms
21,120 KB
testcase_27 AC 28 ms
19,968 KB
testcase_28 AC 30 ms
19,968 KB
testcase_29 AC 28 ms
20,096 KB
testcase_30 AC 22 ms
19,584 KB
testcase_31 AC 28 ms
20,096 KB
testcase_32 AC 23 ms
19,328 KB
testcase_33 AC 30 ms
20,480 KB
testcase_34 AC 29 ms
20,096 KB
testcase_35 AC 29 ms
20,224 KB
testcase_36 AC 24 ms
19,584 KB
testcase_37 AC 24 ms
19,840 KB
testcase_38 AC 30 ms
20,096 KB
testcase_39 AC 23 ms
19,584 KB
testcase_40 AC 31 ms
20,224 KB
testcase_41 AC 31 ms
20,480 KB
testcase_42 AC 31 ms
20,480 KB
testcase_43 AC 32 ms
20,608 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)
    {
        var aL = p.a.Length;
        if (aL <= 2 && p.score != 0) { ans.Add(p.score); 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