結果

問題 No.3210 Fixed Sign Sequense
ユーザー GOTKAKO
提出日時 2025-07-25 21:23:46
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 12 ms / 2,000 ms
コード長 885 bytes
コンパイル時間 1,754 ms
コンパイル使用メモリ 198,384 KB
実行使用メモリ 7,716 KB
最終ジャッジ日時 2025-07-25 21:23:53
合計ジャッジ時間 3,302 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 38
権限があれば一括ダウンロードができます

ソースコード

diff #

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

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    int N; cin >> N;
    string s; cin >> s;
    vector<int> L(N),R(N);
    for(int i=0; i<N; i++){
        if(s.at(i) == '-') L.at(i) = 1;
        else if(s.at(i) == '+') R.at(i) = 1;
    }
    for(int i=1; i<N; i++) L.at(i) += L.at(i-1);
    for(int i=N-2; i>=0; i--) R.at(i) += R.at(i+1);

    int answer = 0;
    for(int i=0; i<N; i++){
        int now = 0;
        if(s.at(i) == '0'){
            now++;
            if(i < N-1) now += R.at(i+1);
            if(i) now += L.at(i-1);
        }
        else if(s.at(i) == '-'){
            now = L.at(i);
            if(i < N-1) now += R.at(i+1);
        }
        else{
            now = R.at(i);
            if(i) now += L.at(i-1);
        }
        answer = max(answer,now);
    }
    cout << answer << endl;
}
0