結果

問題 No.3210 Fixed Sign Sequense
ユーザー asmin
提出日時 2025-07-25 21:25:59
言語 C++17(gcc12)
(gcc 12.3.0 + boost 1.87.0)
結果
AC  
実行時間 7 ms / 2,000 ms
コード長 659 bytes
コンパイル時間 6,584 ms
コンパイル使用メモリ 210,164 KB
実行使用メモリ 7,720 KB
最終ジャッジ日時 2025-07-25 21:26:12
合計ジャッジ時間 8,597 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 38
権限があれば一括ダウンロードができます

ソースコード

diff #

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



void solve(){
    int N; cin >> N;
    int cnt0 = 0, cnt1 = 0;
    string S; cin >> S;
    for(auto c: S){
        if(c == '+') ++cnt1;
    }
    int ans = cnt0 + cnt1;
    for(auto c: S){
        ans = max(ans, cnt0 + cnt1);
        if(c == '-') ++cnt0;
        if(c == '+') --cnt1;
        if(c == '0') ans = max(ans, cnt1 + cnt0 + 1);
        ans = max(ans, cnt0 + cnt1);
    }
    cout << ans << "\n";
    
}


int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << setprecision(10) << fixed;


    int T;
    T = 1;
    //cin >> T;
    for(;T--;) solve();
}

0