結果
| 問題 |
No.345 最小チワワ問題
|
| コンテスト | |
| ユーザー |
okazuki
|
| 提出日時 | 2016-02-29 20:11:35 |
| 言語 | C#(csc) (csc 3.9.0) |
| 結果 |
AC
|
| 実行時間 | 31 ms / 2,000 ms |
| コード長 | 1,492 bytes |
| コンパイル時間 | 2,566 ms |
| コンパイル使用メモリ | 108,800 KB |
| 実行使用メモリ | 19,328 KB |
| 最終ジャッジ日時 | 2024-09-25 11:35:23 |
| 合計ジャッジ時間 | 3,021 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 29 |
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc) Copyright (C) Microsoft Corporation. All rights reserved.
ソースコード
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;
}
}
}
}
okazuki