結果

問題 No.1433 Two color sequence
ユーザー koi_kotyakoi_kotya
提出日時 2021-03-19 22:07:07
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,142 bytes
コンパイル時間 1,650 ms
コンパイル使用メモリ 171,732 KB
実行使用メモリ 13,696 KB
最終ジャッジ日時 2024-04-29 17:01:54
合計ジャッジ時間 7,168 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 114 ms
13,568 KB
testcase_04 AC 106 ms
13,568 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 2 ms
5,376 KB
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair<int,int> P;

#define p_ary(ary,a,b) do { cout << "["; for (int count = (a);count < (b);++count) cout << ary[count] << ((b)-1 == count ? "" : ", "); cout << "]\n"; } while(0)
#define p_map(map,it) do {cout << "{";for (auto (it) = map.begin();;++(it)) {if ((it) == map.end()) {cout << "}\n";break;}else cout << "" << (it)->first << "=>" << (it)->second << ", ";}}while(0)

template<typename T1,typename T2>ostream& operator<<(ostream& os,const pair<T1,T2>& a) {os << "(" << a.first << ", " << a.second << ")";return os;}

const char newl = '\n';

int main() {
    int n;
    string s;
    multiset<int> st;
    cin >> n >> s;
    vector<int> a(n+1,0);
    for (int i = 0;i < n;++i) cin >> a[i+1];
    for (int i = 0;i < n;++i) if (s[i] == 'R') a[i+1] *= -1;
    for (int i = 0;i < n;++i) a[i+1] += a[i];
    for (int i = 0;i < n+1;++i) st.insert(a[i]);
    int ans = 0;
    for (int i = 0;i < n;++i) {
        ans = max(ans,abs(*st.begin()-a[i]));
        ans = max(ans,abs(*prev(st.end())-a[i]));
        st.erase(st.find(a[i]));
    }
    cout << ans << newl;
}
0