結果
| 問題 | No.1433 Two color sequence | 
| コンテスト | |
| ユーザー |  bluemegane | 
| 提出日時 | 2021-03-26 07:49:01 | 
| 言語 | C#(csc) (csc 3.9.0) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 116 ms / 2,000 ms | 
| コード長 | 776 bytes | 
| コンパイル時間 | 825 ms | 
| コンパイル使用メモリ | 114,584 KB | 
| 実行使用メモリ | 44,160 KB | 
| 最終ジャッジ日時 | 2024-11-27 18:07:01 | 
| 合計ジャッジ時間 | 4,099 ms | 
| ジャッジサーバーID (参考情報) | judge5 / judge2 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 3 | 
| other | AC * 21 | 
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc) Copyright (C) Microsoft Corporation. All rights reserved.
ソースコード
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));
    }
}
            
            
            
        