結果

問題 No.999 てん vs. ほむ
ユーザー tsushimatsushima
提出日時 2020-02-29 08:21:43
言語 C#(csc)
(csc 3.9.0)
結果
WA  
実行時間 -
コード長 1,659 bytes
コンパイル時間 3,486 ms
コンパイル使用メモリ 105,600 KB
実行使用メモリ 43,136 KB
最終ジャッジ日時 2024-04-21 21:27:28
合計ジャッジ時間 5,157 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 25 ms
18,816 KB
testcase_01 AC 25 ms
19,200 KB
testcase_02 AC 25 ms
19,072 KB
testcase_03 AC 25 ms
19,200 KB
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 AC 29 ms
19,584 KB
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 AC 89 ms
37,632 KB
testcase_18 AC 89 ms
37,376 KB
testcase_19 AC 89 ms
37,760 KB
testcase_20 AC 94 ms
37,376 KB
testcase_21 AC 120 ms
42,880 KB
testcase_22 AC 117 ms
42,496 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
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.Linq;
using System.Collections.Generic;

class Program
{
    static void Main(string[] args)
    {
        var sol = new Solve();
        sol.Exec();
    }
}

class Solve
{
    public void Exec()
    {
        var N = int.Parse(Console.ReadLine());
        var A = Console.ReadLine().Split().Select(int.Parse).ToArray();

        var acumFoward = new List<int>();
        var acumBack = new List<int>();
        for (var i = 1; i < 2 * N; i+=2)
        {
            acumFoward.Add(A[i - 1] - A[i]);
            acumBack.Add(A[A.Length - 1 - i + 1] - A[A.Length - 1 - i]);
        }

        var left = 0;
        var right = 0;

        var ans = 0L;
        var correction = 0;
        for (var i = 0; i < N; i++)
        {
            if (acumFoward[left] > acumBack[right])
            {
                ans += acumFoward[left];
                left++;
                if (correction != 0)
                {
                    right -= correction;
                    correction = 0;
                }
            }
            else if (acumFoward[left] < acumBack[right])
            {
                ans += acumBack[right];
                right++;
                if (correction != 0)
                {
                    left -= correction;
                    correction = 0;
                }
            }
            else
            {
                if (i == N - 1)
                    left -= correction;

                ans += acumFoward[left];
                correction++;
                left++;
                right++;
            }
        }

        Console.WriteLine(ans);
    }
}

public class Util
{
}
0