結果

問題 No.929 よくあるボールを移動するやつ
ユーザー bluemeganebluemegane
提出日時 2021-04-24 17:15:16
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 58 ms / 2,000 ms
コード長 814 bytes
コンパイル時間 849 ms
コンパイル使用メモリ 111,412 KB
実行使用メモリ 33,636 KB
最終ジャッジ日時 2024-07-04 09:07:49
合計ジャッジ時間 2,230 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 12
権限があれば一括ダウンロードができます
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc)
Copyright (C) Microsoft Corporation. All rights reserved.

ソースコード

diff #

using System.Linq;
using System.Collections.Generic;
using static System.Math;
using System;

public class Hello
{
    static void Main()
    {
        var n = int.Parse(Console.ReadLine().Trim());
        string[] line = Console.ReadLine().Trim().Split(' ');
        var a = Array.ConvertAll(line, int.Parse);
        getAns(n, a);
    }
    static void getAns(int n, int[] a)
    {
        var b0 = new List<int>();
        var b1 = new List<int>();
        for (int i = 0; i < n; i++)
        {
            if (a[i] == 0) b0.Add(i);
            else
            {
                for (int j = 0; j < a[i] - 1; j++) b1.Add(i);
            }
        }
        var bL = b0.Count();
        var count = 0L;
        for (int i = 0; i < bL; i++) count += Abs(b0[i] - b1[i]);
        Console.WriteLine(count);
    }
}
0