結果

問題 No.1433 Two color sequence
ユーザー bluemeganebluemegane
提出日時 2021-03-26 07:49:01
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 120 ms / 2,000 ms
コード長 776 bytes
コンパイル時間 806 ms
コンパイル使用メモリ 112,160 KB
実行使用メモリ 52,568 KB
最終ジャッジ日時 2024-05-05 18:14:02
合計ジャッジ時間 4,174 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 26 ms
24,296 KB
testcase_01 AC 26 ms
25,908 KB
testcase_02 AC 26 ms
26,084 KB
testcase_03 AC 82 ms
38,148 KB
testcase_04 AC 82 ms
40,344 KB
testcase_05 AC 25 ms
24,236 KB
testcase_06 AC 25 ms
24,368 KB
testcase_07 AC 25 ms
24,240 KB
testcase_08 AC 116 ms
52,568 KB
testcase_09 AC 117 ms
50,876 KB
testcase_10 AC 114 ms
46,164 KB
testcase_11 AC 116 ms
46,376 KB
testcase_12 AC 118 ms
50,888 KB
testcase_13 AC 118 ms
48,836 KB
testcase_14 AC 118 ms
48,804 KB
testcase_15 AC 117 ms
49,312 KB
testcase_16 AC 118 ms
51,092 KB
testcase_17 AC 117 ms
49,444 KB
testcase_18 AC 118 ms
46,896 KB
testcase_19 AC 118 ms
49,164 KB
testcase_20 AC 120 ms
49,044 KB
testcase_21 AC 118 ms
49,060 KB
testcase_22 AC 117 ms
49,068 KB
testcase_23 AC 117 ms
49,204 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc)
Copyright (C) Microsoft Corporation. All rights reserved.

ソースコード

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