結果

問題 No.1433 Two color sequence
ユーザー bluemeganebluemegane
提出日時 2021-03-26 07:40:43
言語 C#(csc)
(csc 3.9.0)
結果
WA  
実行時間 -
コード長 773 bytes
コンパイル時間 786 ms
コンパイル使用メモリ 65,424 KB
実行使用メモリ 49,744 KB
最終ジャッジ日時 2023-08-18 12:47:28
合計ジャッジ時間 5,465 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 56 ms
20,692 KB
testcase_01 AC 58 ms
20,748 KB
testcase_02 AC 57 ms
20,804 KB
testcase_03 AC 118 ms
37,960 KB
testcase_04 AC 117 ms
36,008 KB
testcase_05 AC 57 ms
20,812 KB
testcase_06 AC 57 ms
22,744 KB
testcase_07 AC 56 ms
20,696 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 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 int[n];
        b[0] = s[0] == 'B' ? -a[0] : a[0];
        var tmax = Max(0, b[0]);
        var tmin = Min(0, b[0]);
        for (int i = 1; i < n; i++)
        {
            b[i] = s[i] == 'R' ? b[i - 1] + a[i] : b[i - 1] - a[i];
            tmax = Max(tmax, b[i]);
            tmin = Min(tmin, b[i]);
        }
        Console.WriteLine(Abs(tmax - tmin));
    }
}
0