結果

問題 No.33 アメーバがたくさん
ユーザー 14番14番
提出日時 2016-04-03 16:53:15
言語 C#(csc)
(csc 3.9.0)
結果
TLE  
実行時間 -
コード長 3,628 bytes
コンパイル時間 3,283 ms
コンパイル使用メモリ 111,692 KB
実行使用メモリ 24,188 KB
最終ジャッジ日時 2023-10-24 20:16:43
合計ジャッジ時間 8,774 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 26 ms
24,188 KB
testcase_01 AC 26 ms
24,188 KB
testcase_02 AC 25 ms
24,188 KB
testcase_03 AC 25 ms
24,184 KB
testcase_04 AC 23 ms
24,184 KB
testcase_05 AC 24 ms
24,184 KB
testcase_06 AC 25 ms
24,184 KB
testcase_07 AC 26 ms
24,184 KB
testcase_08 TLE -
testcase_09 -- -
testcase_10 -- -
権限があれば一括ダウンロードができます
コンパイルメッセージ
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.Text;

class Program
{
    public void Proc()
    {
        Reader.IsDebug = false;
        int[] inpt = Reader.GetInt();
        int amebaCount = inpt[0];
        int moveLen = inpt[1];
        int maxStep = inpt[2];

        inpt = Reader.GetInt();
        for (int i = 0; i < inpt.Length; i++)
        {
            AmebaList.Add(new Ameba(inpt[i], inpt[i]));
        }

        for (int i = 0; i < maxStep; i++)
        {
            List<Ameba> nextList = new List<Ameba>();
            foreach (Ameba am in AmebaList)
            {
                nextList.Add(am.Move(moveLen * -1));
                nextList.Add(am);
                nextList.Add(am.Move(moveLen));
            }
            nextList.Sort((a, b) =>
            {
                if (a.From < b.From)
                {
                    return -1;
                }
                if (a.From > b.From)
                {
                    return 1;
                }
                if (a.To < b.To)
                {
                    return -1;
                }
                if (a.To > b.To)
                {
                    return 1;
                }
                return 0;
            });
            for (int j = nextList.Count - 1; j >= 1; j--)
            {
                Ameba current = nextList[j];
                Ameba before = nextList[j - 1];
                if (current.From >= before.From && current.From <= before.To)
                {
                    long newFrom = before.From;
                    long newTo = Math.Max(before.To, current.To);
                    Ameba newIns = new Ameba(newFrom, newTo);
                    nextList[j - 1] = newIns;
                    nextList.RemoveAt(j);
                }
                this.AmebaList = nextList;
            }
        }
        long ans = 0;
        foreach (Ameba am in this.AmebaList)
        {
            ans += (am.To - am.From + 1);
        }
        Console.WriteLine(ans.ToString("####################################################0"));
    }

    private List<Ameba> AmebaList = new List<Ameba>();
    public class Ameba
    {
        public long From;
        public long To;
        public Ameba(long from, long to)
        {
            this.From = from;
            this.To = to;
        }
        public Ameba Move(int moveLen)
        {
            return new Ameba(this.From + moveLen, this.To + moveLen);
        }
    }

    public class Reader
    {
        public static bool IsDebug = true;
        private static String PlainInput = @"


2 3 1
0 2




 
";
        private static System.IO.StringReader Sr = null;
        public static string ReadLine()
        {
            if (IsDebug)
            {
                if (Sr == null)
                {
                    Sr = new System.IO.StringReader(PlainInput.Trim());
                }
                return Sr.ReadLine();
            }
            else
            {
                return Console.ReadLine();
            }
        }
        public static int[] GetInt(char delimiter = ' ', bool trim = false)
        {
            string inptStr = ReadLine();
            if (trim)
            {
                inptStr = inptStr.Trim();
            }
            string[] inpt = inptStr.Split(delimiter);
            int[] ret = new int[inpt.Length];
            for (int i = 0; i < inpt.Length; i++)
            {
                ret[i] = int.Parse(inpt[i]);
            }
            return ret;
        }
    }
    static void Main()
    {
        Program prg = new Program();
        prg.Proc();
    }
}
0