結果
問題 | No.1433 Two color sequence |
ユーザー |
|
提出日時 | 2021-03-22 20:29:32 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 98 ms / 2,000 ms |
コード長 | 2,427 bytes |
コンパイル時間 | 1,148 ms |
コンパイル使用メモリ | 108,736 KB |
実行使用メモリ | 11,520 KB |
最終ジャッジ日時 | 2024-11-24 07:49:39 |
合計ジャッジ時間 | 4,151 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 21 |
ソースコード
#include<algorithm>#include<bitset>#include<cmath>#include<complex>#include<deque>#include<functional>#include<iomanip>#include<iostream>#include<iterator>#include<map>#include<numeric>#include<queue>#include<set>#include<stack>#include<string>#include<unordered_map>#include<unordered_set>#include<utility>#include<vector>#include<chrono>using namespace std;#define rep(i,n) for(int i=0; i<(n); i++)#define FOR(i,x,n) for(int i=x; i<(n); i++)#define vint(a,n) vint a(n); rep(i, n) cin >> a[i];#define vll(a,n) vll a(n); rep(i, n) cin >> a[i];#define ALL(n) begin(n),end(n)#define RALL(n) rbegin(n),rend(n)#define MOD (1000000007)// #define MOD (998244353)#define INF (1e9+7)#define INFL (2e18)typedef long long ll;typedef unsigned int ui;typedef unsigned long long ull;using vint=vector<int>;using vll=vector<ll>;using vbool=vector<bool>;using P=pair<ll,ll>;template<class T>using arr=vector<vector<T>>;template<class T>int popcount(T &a){int c=0; rep(i, 8*(int)sizeof(a)){if((a>>i)&1) c++;} return c;}template<class T>void pl(T x){cout << x << " ";}template<class T>void pr(T x){cout << x << endl;}template <class T, class... Ts> inline void pr(T Tar, Ts... ts) { std::cout << Tar << " "; pr(ts...); return; }template<class T>void prvec(vector<T>& a){rep(i, (int)a.size()-1){pl(a[i]);} pr(a.back());}template<class T>void prarr(arr<T>& a){rep(i, (int)a.size()) if(a[i].empty()) pr(""); else prvec(a[i]);}template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }template<typename A, size_t N, typename T> void Fill(A (&array)[N], const T &val){fill( (T*)array, (T*)(array+N), val );}int main(){int n; cin >> n;string s; cin >> s;vll(a, n);vll R(n, 0), B(n, 0);vll RB(n), BR(n);ll RBmin = INFL, BRmin = INFL;ll ans = -INFL;rep(i, n){if(i != 0){R[i] += R[i-1];B[i] += B[i-1];}if(s[i]=='R'){R[i] += a[i];}else{B[i] += a[i];}RB[i] = R[i] - B[i];BR[i] = B[i] - R[i];chmin(RBmin, RB[i]);chmin(BRmin, BR[i]);ll p = RB[i] - min(RBmin, 0LL);ll q = BR[i] - min(BRmin, 0LL);chmax(ans, max(p, q));}// prvec(R);// prvec(B);pr(ans);return 0;}