結果

問題 No.33 アメーバがたくさん
ユーザー 14番14番
提出日時 2016-05-29 16:06:54
言語 C#(csc)
(csc 3.9.0)
結果
WA  
実行時間 -
コード長 3,831 bytes
コンパイル時間 4,142 ms
コンパイル使用メモリ 112,644 KB
実行使用メモリ 25,588 KB
最終ジャッジ日時 2023-10-24 20:18:32
合計ジャッジ時間 7,597 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 30 ms
25,576 KB
testcase_01 AC 29 ms
25,392 KB
testcase_02 AC 29 ms
25,392 KB
testcase_03 AC 30 ms
25,392 KB
testcase_04 AC 30 ms
25,404 KB
testcase_05 AC 29 ms
25,404 KB
testcase_06 WA -
testcase_07 WA -
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;
using System.Linq;

class Program
{
    public void Proc()
    {
        Reader.IsDebug = false;
        long[] inpt = Reader.ReadLine().Split(' ').Select(a=>long.Parse(a)).ToArray();
        int amebaCount = (int)inpt[0];
        Ameba.Diff =  inpt[1];
        long jikan = inpt[2];
        inpt = Reader.ReadLine().Split(' ').Select(a=>long.Parse(a)).ToArray();
        List<Ameba> list = new List<Ameba>();
        for(int i=0; i<amebaCount; i++) {
            Ameba amb = new Ameba(inpt[i]);
            amb.JikanKeika(jikan);
            list.Add(amb);
        }
        
        list.Sort((a,b)=>{
           if(a.First < b.First) {
               return -1;
           } else if(a.First> b.First) {
               return 1;
           }
           return 0;
        });
        
        while (list.Count > 1)
        {
            bool marged = false;
            int last = list.Count;
            for(int i=0; i<last; i++) {
                Ameba[] target = list.Where(a=>list[i].CanMarge(a)).ToArray();
                if(target.Length > 1) {
                    Ameba mg = list[i];
                    target.ToList().ForEach(a=>mg = mg.Marget(a));
                    list.RemoveAll(a=>list[i].CanMarge(a));
                    list.Insert(i, mg);
                    marged = true;
                    break;
                }
            }
            if(!marged) {
                break;
            }
        }
        long ans = 0;
        list.ForEach(a=>ans+=a.Count());
        Console.WriteLine(ans);
    }

    public class Ameba {
        public long First;
        public long Last;
        
        public static long Diff;
        
        public Ameba(long pos) {
            this.First = pos;
            this.Last = pos;
        }
        
        public Ameba(long first, long last) {
            this.First = first;
            this.Last = last;
        }
        
        public Ameba Marget(Ameba target) {
            Ameba mg = new Ameba(Math.Min(this.First,target.First), Math.Max(this.Last, target.Last));
            return mg;
        }
        
        public long Count() {
            return (this.Last - this.First) / Diff + 1;
        }
        
        public void JikanKeika(long num) {
            this.First = this.First - (num * Diff);
            this.Last = this.Last + (num * Diff);
        }
        
        public bool CanMarge(Ameba target) {
            Ameba saki;
            Ameba ato;
            if(this.First < target.First) {
                saki = this;
                ato = target;
            } else if(this.First > target.First)
            {
                saki = target;
                ato = this;
            } else
            {
                return true;
            }
            
            if((ato.First - saki.First) % Diff > 0) {
                return false;
            }
            
            if(ato.First <= saki.Last) {
                return true;
            }
            if(ato.First - saki.Last == Diff) {
                return true;
            }
            return false;
        }
    }

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



2 3 2
0 6




";
        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();
            }
        }
    }
    static void Main()
    {
        Program prg = new Program();
        prg.Proc();
    }
}
0