結果

問題 No.345 最小チワワ問題
ユーザー okazukiokazuki
提出日時 2016-02-29 20:11:35
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 33 ms / 2,000 ms
コード長 1,492 bytes
コンパイル時間 1,434 ms
コンパイル使用メモリ 111,968 KB
実行使用メモリ 25,300 KB
最終ジャッジ日時 2023-10-26 03:41:16
合計ジャッジ時間 3,464 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 31 ms
25,224 KB
testcase_01 AC 32 ms
25,292 KB
testcase_02 AC 33 ms
25,300 KB
testcase_03 AC 33 ms
25,300 KB
testcase_04 AC 32 ms
25,296 KB
testcase_05 AC 32 ms
25,296 KB
testcase_06 AC 32 ms
25,296 KB
testcase_07 AC 31 ms
25,208 KB
testcase_08 AC 31 ms
25,208 KB
testcase_09 AC 31 ms
25,204 KB
testcase_10 AC 31 ms
25,224 KB
testcase_11 AC 31 ms
25,208 KB
testcase_12 AC 31 ms
25,232 KB
testcase_13 AC 31 ms
25,208 KB
testcase_14 AC 33 ms
25,300 KB
testcase_15 AC 32 ms
25,224 KB
testcase_16 AC 32 ms
25,292 KB
testcase_17 AC 32 ms
25,300 KB
testcase_18 AC 32 ms
25,300 KB
testcase_19 AC 32 ms
25,296 KB
testcase_20 AC 31 ms
25,236 KB
testcase_21 AC 31 ms
25,236 KB
testcase_22 AC 31 ms
25,224 KB
testcase_23 AC 32 ms
25,292 KB
testcase_24 AC 31 ms
25,300 KB
testcase_25 AC 32 ms
25,292 KB
testcase_26 AC 31 ms
25,292 KB
testcase_27 AC 32 ms
25,300 KB
testcase_28 AC 31 ms
25,232 KB
testcase_29 AC 31 ms
25,300 KB
testcase_30 AC 31 ms
25,300 KB
testcase_31 AC 30 ms
25,204 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc)
Copyright (C) Microsoft Corporation. All rights reserved.

ソースコード

diff #

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

namespace ConsoleApplication6
{
    class Program
    {
        static void Main(string[] args)
        {
            var s = Console.ReadLine();
            var cww = s.Aggregate(new { Cwws = new List<Cww>(), Index = 0 }, (l, x) =>
            {
                foreach (var item in l.Cwws)
                {
                    item.Push(l.Index, x);
                }

                if (x == 'c')
                {
                    l.Cwws.Add(new Cww(l.Index));
                }
                return new { Cwws = l.Cwws, Index = l.Index + 1 };
            })
            .Cwws
            .Where(x => x.IsFinish)
            .OrderBy(x => x.Length)
            .FirstOrDefault();
            Console.WriteLine(cww?.Length ?? -1);
        }
    }

    class Cww
    {
        private bool FindFirstW { get; set; }
        public int StartIndex { get; }
        public int? Length { get; private set; }

        public bool IsFinish => this.Length != null;

        public Cww(int startIndex)
        {
            this.StartIndex = startIndex;
        }

        public void Push(int index, char w)
        {
            if (this.IsFinish) { return; }
            if (w != 'w') { return; }

            if (this.FindFirstW)
            {
                this.Length = index - this.StartIndex + 1;
            }
            else
            {
                this.FindFirstW = true;
            }
        }
    }
}
0