結果

問題 No.1433 Two color sequence
コンテスト
ユーザー 夜
提出日時 2021-03-19 22:00:03
言語 C++14
(gcc 15.3.0 + boost 1.92.0 + ACL)
コンパイル:
g++-15 -O2 -lm -std=c++14 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
WA  
実行時間 -
コード長 844 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 439 ms
コンパイル使用メモリ 107,736 KB
実行使用メモリ 9,924 KB
最終ジャッジ日時 2026-09-26 01:58:11
合計ジャッジ時間 4,888 ms
ジャッジサーバーID
(参考情報)
judge2_0 / judge1_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 19 WA * 2
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
#include <stdio.h>
#include <queue>
#include <deque>
#include <cstdio>
#include <set>
#include <map>
#include <bitset>
#include <stack>
#include <cctype>
using namespace std;
long long a[200020];
long long sum[200020] = {};
int main() {
	int n;
	string s;
	cin >> n >> s;
	long long ans = -100000000000007, ma = 0, mi = 0;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		if (s[i] == 'R') {
			sum[i] -= a[i];
		}
		else {
			sum[i] += a[i];
		}
		if (i != 0) {
			sum[i] += sum[i - 1];
			if (abs(sum[i] - ma) > ans) {
				ans = abs(sum[i] - ma);
			}
			if (abs(sum[i] - mi) > ans) {
				ans = abs(sum[i] - mi);
			}
		}
		if (ma < sum[i]) {
			ma = sum[i];
		}
		if (mi > sum[i]) {
			mi = sum[i];
		}
	}
	cout << ans << endl;

}
0