結果
| 問題 |
No.33 アメーバがたくさん
|
| コンテスト | |
| ユーザー |
14番
|
| 提出日時 | 2016-05-29 16:06:54 |
| 言語 | C#(csc) (csc 3.9.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 3,831 bytes |
| コンパイル時間 | 1,037 ms |
| コンパイル使用メモリ | 114,324 KB |
| 実行使用メモリ | 37,700 KB |
| 最終ジャッジ日時 | 2024-09-24 15:16:53 |
| 合計ジャッジ時間 | 7,945 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 6 WA * 2 TLE * 1 -- * 2 |
コンパイルメッセージ
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.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();
}
}
14番