結果

問題 No.1433 Two color sequence
ユーザー 沙耶花
提出日時 2021-03-19 21:48:44
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 52 ms / 2,000 ms
コード長 673 bytes
コンパイル時間 5,883 ms
コンパイル使用メモリ 250,532 KB
最終ジャッジ日時 2025-01-19 18:20:41
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 21
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:31:22: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   31 |                 scanf("%lld",&A[i]);
      |                 ~~~~~^~~~~~~~~~~~~~

ソースコード

diff #

#include <stdio.h>
#include <bits/stdc++.h>
#include <atcoder/all>
using namespace atcoder;
using mint = modint998244353;
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define Inf 1000000001

long long get(vector<long long> A){
	long long mini = 0LL;
	long long cur = 0LL;
	long long ret = 0LL;
	rep(i,A.size()){
		cur += A[i];
		ret = max(ret,cur - mini);
		mini = min(mini,cur);
	}
	return ret;
}

int main(){
	int N;
	cin>>N;
	
	string S;
	cin>>S;
	
	vector<long long> A(N);
	rep(i,N){
		scanf("%lld",&A[i]);
		if(S[i]=='B')A[i] *= -1;
	}
	
	long long ans = get(A);
	rep(i,N)A[i] *= -1;
	ans = max(ans,get(A));
	
	cout<<ans<<endl;
	
    return 0;
}
0