結果

問題 No.1433 Two color sequence
ユーザー bluemeganebluemegane
提出日時 2021-03-26 07:59:43
言語 C#(csc)
(csc 3.9.0)
結果
WA  
実行時間 -
コード長 766 bytes
コンパイル時間 1,664 ms
コンパイル使用メモリ 63,892 KB
実行使用メモリ 51,708 KB
最終ジャッジ日時 2023-08-18 13:08:17
合計ジャッジ時間 6,299 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 56 ms
18,812 KB
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 AC 119 ms
40,964 KB
testcase_05 AC 57 ms
22,840 KB
testcase_06 AC 57 ms
20,844 KB
testcase_07 WA -
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 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

using static System.Math;
using System;

public class Hello
{
    static void Main()
    {
        var n = int.Parse(Console.ReadLine().Trim());
        var s = Console.ReadLine().Trim();
        string[] line = Console.ReadLine().Trim().Split(' ');
        var a = Array.ConvertAll(line, int.Parse);
        getAns(n, s, a);
    }
    static void getAns(int n, string s, int[] a)
    {
        var b = new long[n];
        b[0] = s[0] == 'R' ? a[0] : -a[0];
        long tmax = Max(0, b[0]);
        long tmin = Min(0, b[0]);
        for (int i = 1; i < n; i++)
        {
            b[i] = b[i - 1] + s[i] == 'R' ? a[i] : -a[i];
            tmax = Max(tmax, b[i]);
            tmin = Min(tmin, b[i]);
        }
        Console.WriteLine(Abs(tmax - tmin));
    }
}
0