コード例 #1
0
        static void Main()
        {
            var records = new List <long>();

            while (true)
            {
                try
                {
                    using (var sc = new SetConsole())
                    {
                        var sw = new Stopwatch();
                        sw.Start();
                        Program.Main(null);
                        sw.Stop();
                        records.Add(sw.ElapsedMilliseconds);
                        sw.Reset();
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex);
                    Console.WriteLine("Process was supended");
                }
                if (records.Any())
                {
                    Console.WriteLine($"AveTime is {records.Average()}ms");
                }
            }
        }
コード例 #2
0
        public static void Main(string[] args)
        {
            using (var sc = new SetConsole())
            {
                var input = GetArrayIntInput();

                var str   = Console.ReadLine().AsEnumerable <char>().Select(c => c.ToString().ToInt()).ToArray();
                var dic   = new Dictionary <int, int>();
                var queue = new Queue <int>();
                for (int i = 0; i < input[0]; i++)
                {
                    if (0 == str[i])
                    {
                        queue.Enqueue(i);
                    }
                    else
                    {
                        if (queue.Any())
                        {
                            dic.Add(queue.Peek(), queue.Count);
                            queue.Clear();
                        }
                    }
                }
                if (queue.Any())
                {
                    dic.Add(queue.Peek(), queue.Count);
                    queue.Clear();
                }

                dic = new Dictionary <int, int>(dic.OrderByDescending(d => d.Value).ThenByDescending(d => d.Key));
                for (int i = 0; i < Math.Min(input[1], dic.Count); i++)
                {
                    var tmp = dic.ElementAt(i);
                    for (int j = tmp.Key; j < tmp.Key + tmp.Value; j++)
                    {
                        str[j]++;
                    }
                }
                CWrite(string.Join("", str).Split('0').Max(s => s.Length));
            }
        }