結果

問題 No.455 冬の大三角
ユーザー くれちーくれちー
提出日時 2017-10-10 00:35:40
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 37 ms / 2,000 ms
コード長 9,699 bytes
コンパイル時間 2,786 ms
コンパイル使用メモリ 123,776 KB
実行使用メモリ 27,628 KB
最終ジャッジ日時 2024-06-30 03:16:15
合計ジャッジ時間 5,266 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 34 ms
27,264 KB
testcase_01 AC 34 ms
25,332 KB
testcase_02 AC 35 ms
27,348 KB
testcase_03 AC 35 ms
25,520 KB
testcase_04 AC 36 ms
27,460 KB
testcase_05 AC 36 ms
25,292 KB
testcase_06 AC 35 ms
25,320 KB
testcase_07 AC 35 ms
27,364 KB
testcase_08 AC 37 ms
25,432 KB
testcase_09 AC 36 ms
25,200 KB
testcase_10 AC 35 ms
25,072 KB
testcase_11 AC 35 ms
27,472 KB
testcase_12 AC 35 ms
25,292 KB
testcase_13 AC 35 ms
25,456 KB
testcase_14 AC 35 ms
25,292 KB
testcase_15 AC 34 ms
25,328 KB
testcase_16 AC 37 ms
25,460 KB
testcase_17 AC 35 ms
25,328 KB
testcase_18 AC 34 ms
27,216 KB
testcase_19 AC 34 ms
27,344 KB
testcase_20 AC 35 ms
25,456 KB
testcase_21 AC 33 ms
25,328 KB
testcase_22 AC 34 ms
25,452 KB
testcase_23 AC 34 ms
27,344 KB
testcase_24 AC 35 ms
27,368 KB
testcase_25 AC 34 ms
25,328 KB
testcase_26 AC 34 ms
25,292 KB
testcase_27 AC 33 ms
25,068 KB
testcase_28 AC 34 ms
25,456 KB
testcase_29 AC 34 ms
25,456 KB
testcase_30 AC 35 ms
25,196 KB
testcase_31 AC 35 ms
25,072 KB
testcase_32 AC 34 ms
25,076 KB
testcase_33 AC 37 ms
27,352 KB
testcase_34 AC 34 ms
25,072 KB
testcase_35 AC 36 ms
25,556 KB
testcase_36 AC 35 ms
25,324 KB
testcase_37 AC 36 ms
25,560 KB
testcase_38 AC 35 ms
25,648 KB
testcase_39 AC 35 ms
25,196 KB
testcase_40 AC 36 ms
25,460 KB
testcase_41 AC 35 ms
27,348 KB
testcase_42 AC 35 ms
25,392 KB
testcase_43 AC 35 ms
27,628 KB
testcase_44 AC 35 ms
25,204 KB
testcase_45 AC 34 ms
27,368 KB
testcase_46 AC 36 ms
25,456 KB
testcase_47 AC 35 ms
25,200 KB
testcase_48 AC 36 ms
23,480 KB
testcase_49 AC 34 ms
25,156 KB
testcase_50 AC 34 ms
25,204 KB
testcase_51 AC 35 ms
27,260 KB
testcase_52 AC 34 ms
27,336 KB
testcase_53 AC 35 ms
25,516 KB
testcase_54 AC 35 ms
27,620 KB
testcase_55 AC 35 ms
25,440 KB
testcase_56 AC 35 ms
27,368 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.Diagnostics;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Text;
using System.Threading.Tasks;
using CSharp7.Library;
using static System.Math;
using static System.Linq.Enumerable;
using static CSharp7.Library.Extentions;

namespace CSharp7
{
    public static class Program
    {
        public static void Solve(IO io)
        {
            var (h, w) = io.Read<int, int>();
            var sky = io.ReadMany(h, s => s.Select(c => c == '*').ToArray());

            for (var i = 0; i < h; i++)
                for (var j = 0; j < w; j++)
                    if (sky[i][j])
                    {
                        if (sky[i].Count(p => p) == 2) sky[i == 0 ? i + 1 : i - 1][j] = true;
                        else sky[i][j == 0 ? j + 1 : j - 1] = true;
                        goto ExitLoop;
                    }

            ExitLoop:
            io.WriteMany(sky, ps => ps.Select(p => p ? '*' : '-').AsString());
        }

        public static void Main()
        {
            var sw = new StreamWriter(Console.OpenStandardOutput()) { NewLine = "\n" };
#if DEBUG
            sw.AutoFlush = true;
#else
            sw.AutoFlush = false;
#endif
            Console.SetOut(sw);
            Solve(new IO(Console.In, Console.Out));
            Console.Out.Flush();
        }
    }
}

namespace CSharp7.Library
{
    public delegate T Parser<out T>(string str);
    public delegate string Serializer<in T>(T value);

    public class IO
    {
        private static readonly Dictionary<Type, Delegate> _parsers = new Dictionary<Type, Delegate>
        {
            { typeof(string), (Parser<string>)(s => s) },
            { typeof(char), (Parser<char>)char.Parse },
            { typeof(int), (Parser<int>)int.Parse },
            { typeof(long), (Parser<long>)long.Parse },
            { typeof(double), (Parser<double>)double.Parse },
            { typeof(decimal), (Parser<decimal>)decimal.Parse },
            { typeof(BigInteger), (Parser<BigInteger>)BigInteger.Parse },
        };

        private static readonly Dictionary<Type, Delegate> _serializers = new Dictionary<Type, Delegate>
        {
            { typeof(string), (Serializer<string>)(s => s) },
            { typeof(char), (Serializer<char>)(c => c.ToString()) },
            { typeof(int), (Serializer<int>)(i => i.ToString()) },
            { typeof(long), (Serializer<long>)(l => l.ToString()) },
            { typeof(double), (Serializer<double>)(d => d.ToString()) },
            { typeof(decimal), (Serializer<decimal>)(d => d.ToString()) },
            { typeof(BigInteger), (Serializer<BigInteger>)(b => b.ToString()) },
        };

        private TextReader _sr;
        private TextWriter _sw;

        public IO(TextReader sr, TextWriter sw)
        {
            _sr = sr;
            _sw = sw;
        }

        public string ReadLine() => _sr.ReadLine();

        public string ReadWord()
        {
            var sb = new StringBuilder();
            var c = _sr.Read();
            while (c != ' ' && c != '\n') { sb.Append((char)c); c = _sr.Read(); }
            return sb.ToString();
        }

        public T Read<T>(Parser<T> p = null)
            => (p ?? GetParser<T>())(ReadWord());

        public (T1, T2) Read<T1, T2>(Parser<T1> p1 = null, Parser<T2> p2 = null)
            => (Read(p1 ?? GetParser<T1>()), Read(p2 ?? GetParser<T2>()));

        public (T1, T2, T3) Read<T1, T2, T3>(Parser<T1> p1 = null, Parser<T2> p2 = null, Parser<T3> p3 = null)
            => (Read(p1 ?? GetParser<T1>()), Read(p2 ?? GetParser<T2>()), Read(p3 ?? GetParser<T3>()));

        public (T1, T2, T3, T4) Read<T1, T2, T3, T4>(Parser<T1> p1 = null, Parser<T2> p2 = null, Parser<T3> p3 = null, Parser<T4> p4 = null)
            => (Read(p1 ?? GetParser<T1>()), Read(p2 ?? GetParser<T2>()), Read(p3 ?? GetParser<T3>()), Read(p4 ?? GetParser<T4>()));

        public T[] ReadMany<T>(int count, Parser<T> p = null)
        {
            var a = new T[count];
            for (var i = 0; i < count; i++) a[i] = Read(p);
            return a;
        }

        public (T1[], T2[]) ReadMany<T1, T2>(int count, Parser<T1> p1 = null, Parser<T2> p2 = null)
        {
            var a1 = new T1[count];
            var a2 = new T2[count];
            for (var i = 0; i < count; i++) (a1[i], a2[i]) = Read(p1, p2);
            return (a1, a2);
        }

        public (T1[], T2[], T3[]) ReadMany<T1, T2, T3>(int count, Parser<T1> p1 = null, Parser<T2> p2 = null, Parser<T3> p3 = null)
        {
            var a1 = new T1[count];
            var a2 = new T2[count];
            var a3 = new T3[count];
            for (var i = 0; i < count; i++) (a1[i], a2[i], a3[i]) = Read(p1, p2, p3);
            return (a1, a2, a3);
        }

        public (T1[], T2[], T3[], T4[]) ReadMany<T1, T2, T3, T4>(int count, Parser<T1> p1 = null, Parser<T2> p2 = null, Parser<T3> p3 = null, Parser<T4> p4 = null)
        {
            var a1 = new T1[count];
            var a2 = new T2[count];
            var a3 = new T3[count];
            var a4 = new T4[count];
            for (var i = 0; i < count; i++) (a1[i], a2[i], a3[i], a4[i]) = Read(p1, p2, p3, p4);
            return (a1, a2, a3, a4);
        }

        public void Write<T>(T v, Serializer<T> s = null)
        {
            _sw.Write(s?.Invoke(v) ?? GetSerializer<T>()(v));
            _sw.Write(' ');
        }

        public void Write<T1, T2>(T1 v1, T2 v2, Serializer<T1> s1 = null, Serializer<T2> s2 = null)
        {
            Write(v1, s1);
            Write(v2, s2);
        }

        public void Write<T1, T2, T3>(T1 v1, T2 v2, T3 v3, Serializer<T1> s1 = null, Serializer<T2> s2 = null, Serializer<T3> s3 = null)
        {
            Write(v1, s1);
            Write(v2, s2);
            Write(v3, s3);
        }

        public void Write<T1, T2, T3, T4>(T1 v1, T2 v2, T3 v3, T4 v4, Serializer<T1> s1 = null, Serializer<T2> s2 = null, Serializer<T3> s3 = null, Serializer<T4> s4 = null)
        {
            Write(v1, s1);
            Write(v2, s2);
            Write(v3, s3);
            Write(v4, s4);
        }

        public void WriteLine<T>(T v, Serializer<T> s = null)
        {
            Write(v, s);
            _sw.WriteLine();
        }

        public void WriteLine<T1, T2>(T1 v1, T2 v2, Serializer<T1> s1 = null, Serializer<T2> s2 = null)
        {
            Write(v1, v2, s1, s2);
            _sw.WriteLine();
        }

        public void WriteLine<T1, T2, T3>(T1 v1, T2 v2, T3 v3, Serializer<T1> s1 = null, Serializer<T2> s2 = null, Serializer<T3> s3 = null)
        {
            Write(v1, v2, v3, s1, s2, s3);
            _sw.WriteLine();
        }

        public void WriteLine<T1, T2, T3, T4>(T1 v1, T2 v2, T3 v3, T4 v4, Serializer<T1> s1 = null, Serializer<T2> s2 = null, Serializer<T3> s3 = null, Serializer<T4> s4 = null)
        {
            Write(v1, v2, v3, v4, s1, s2, s3, s4);
            _sw.WriteLine();
        }

        public void WriteMany<T>(IEnumerable<T> vs, Serializer<T> s = null)
        {
            foreach (var v in vs) WriteLine(v, s);
        }

        public void WriteMany<T1, T2>(IEnumerable<T1> vs1, IEnumerable<T2> vs2, Serializer<T1> s1 = null, Serializer<T2> s2 = null)
        {
            foreach (var (v1, v2) in vs1.Zip(vs2, ValueTuple.Create)) WriteLine(v1, v2, s1, s2);
        }

        public void WriteMany<T1, T2, T3>(IEnumerable<T1> vs1, IEnumerable<T2> vs2, IEnumerable<T3> vs3, Serializer<T1> s1 = null, Serializer<T2> s2 = null, Serializer<T3> s3 = null)
        {
            foreach (var (v1, v2, v3) in vs1.Zip(vs2, vs3, ValueTuple.Create)) WriteLine(v1, v2, v3, s1, s2, s3);
        }

        public void WriteMany<T1, T2, T3, T4>(IEnumerable<T1> vs1, IEnumerable<T2> vs2, IEnumerable<T3> vs3, IEnumerable<T4> vs4, Serializer<T1> s1 = null, Serializer<T2> s2 = null, Serializer<T3> s3 = null, Serializer<T4> s4 = null)
        {
            foreach (var (v1, v2, v3, v4) in vs1.Zip(vs2, vs3, vs4, ValueTuple.Create)) WriteLine(v1, v2, v3, v4, s1, s2, s3, s4);
        }

        private Parser<T> GetParser<T>() => (Parser<T>)_parsers[typeof(T)];

        private Serializer<T> GetSerializer<T>() => (Serializer<T>)_serializers[typeof(T)];
    }

    public static class Extentions
    {
        public static string AsString(this IEnumerable<char> source) => new string(source.ToArray());

        public static void Swap<T>(ref T x, ref T y)
        {
            var tmp = x; x = y; y = tmp;
        }

        public static IEnumerable<T> Zip<T1, T2, T3, T>(this IEnumerable<T1> first, IEnumerable<T2> second, IEnumerable<T3> thrid, Func<T1, T2, T3, T> resultSelector)
        {
            using (var e1 = first.GetEnumerator())
            using (var e2 = second.GetEnumerator())
            using (var e3 = thrid.GetEnumerator())
            {
                while (e1.MoveNext() && e2.MoveNext() && e3.MoveNext())
                    yield return resultSelector(e1.Current, e2.Current, e3.Current);
            }
        }

        public static IEnumerable<T> Zip<T1, T2, T3, T4, T>(this IEnumerable<T1> first, IEnumerable<T2> second, IEnumerable<T3> thrid, IEnumerable<T4> fourth, Func<T1, T2, T3, T4, T> resultSelector)
        {
            using (var e1 = first.GetEnumerator())
            using (var e2 = second.GetEnumerator())
            using (var e3 = thrid.GetEnumerator())
            using (var e4 = fourth.GetEnumerator())
            {
                while (e1.MoveNext() && e2.MoveNext() && e3.MoveNext() && e4.MoveNext())
                    yield return resultSelector(e1.Current, e2.Current, e3.Current, e4.Current);
            }
        }
    }
}
0