結果

問題 No.929 よくあるボールを移動するやつ
ユーザー bluemeganebluemegane
提出日時 2021-04-24 17:15:16
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 93 ms / 2,000 ms
コード長 814 bytes
コンパイル時間 866 ms
コンパイル使用メモリ 63,980 KB
実行使用メモリ 30,484 KB
最終ジャッジ日時 2023-09-17 13:39:22
合計ジャッジ時間 2,943 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 60 ms
21,436 KB
testcase_01 AC 61 ms
21,488 KB
testcase_02 AC 59 ms
19,252 KB
testcase_03 AC 60 ms
21,244 KB
testcase_04 AC 59 ms
21,452 KB
testcase_05 AC 60 ms
23,552 KB
testcase_06 AC 67 ms
21,500 KB
testcase_07 AC 78 ms
25,028 KB
testcase_08 AC 93 ms
27,236 KB
testcase_09 AC 93 ms
27,452 KB
testcase_10 AC 92 ms
28,272 KB
testcase_11 AC 92 ms
30,484 KB
testcase_12 AC 92 ms
30,384 KB
testcase_13 AC 92 ms
28,328 KB
testcase_14 AC 92 ms
26,456 KB
testcase_15 AC 92 ms
30,372 KB
権限があれば一括ダウンロードができます

ソースコード

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