結果

問題 No.1433 Two color sequence
ユーザー bluemeganebluemegane
提出日時 2021-03-26 07:49:01
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 153 ms / 2,000 ms
コード長 776 bytes
コンパイル時間 861 ms
コンパイル使用メモリ 61,792 KB
実行使用メモリ 50,996 KB
最終ジャッジ日時 2023-08-18 12:56:58
合計ジャッジ時間 5,384 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 54 ms
20,908 KB
testcase_01 AC 54 ms
20,828 KB
testcase_02 AC 55 ms
20,872 KB
testcase_03 AC 117 ms
39,016 KB
testcase_04 AC 113 ms
36,876 KB
testcase_05 AC 54 ms
20,812 KB
testcase_06 AC 54 ms
22,888 KB
testcase_07 AC 53 ms
20,808 KB
testcase_08 AC 151 ms
50,996 KB
testcase_09 AC 145 ms
47,504 KB
testcase_10 AC 143 ms
46,664 KB
testcase_11 AC 140 ms
44,724 KB
testcase_12 AC 147 ms
47,528 KB
testcase_13 AC 148 ms
45,440 KB
testcase_14 AC 144 ms
43,476 KB
testcase_15 AC 141 ms
47,624 KB
testcase_16 AC 150 ms
47,608 KB
testcase_17 AC 143 ms
45,616 KB
testcase_18 AC 147 ms
47,616 KB
testcase_19 AC 148 ms
47,776 KB
testcase_20 AC 148 ms
45,564 KB
testcase_21 AC 153 ms
45,592 KB
testcase_22 AC 145 ms
47,576 KB
testcase_23 AC 144 ms
45,604 KB
権限があれば一括ダウンロードができます

ソースコード

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] == 'B' ? -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] = 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