結果

問題 No.2145 Segment +-
ユーザー ぷらぷら
提出日時 2022-12-02 22:56:42
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 772 bytes
コンパイル時間 2,262 ms
コンパイル使用メモリ 194,516 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-18 08:14:10
合計ジャッジ時間 2,865 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

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

int main() {
    int N;
    string S;
    cin >> N >> S;
    int ans1 = 0,sum1 = 0,f1 = 0;
    for(int i = 0; i < N; i++) {
        if(S[i] == '+' || S[i] == '?') {
            sum1++;
            if(sum1 >= 1) f1 = 0;
        }
        else {
            sum1--;
            if(sum1 < 0 && f1 == 0) {
                f1 = 1;
                ans1++;
            }
        }
    }
    int ans2 = 0,sum2 = 0,f2 = 0;
    for(int i = 0; i < N; i++) {
        if(S[i] == '+') {
            sum2++;
            if(sum2 >= 1) f2 = 0;
        }
        else {
            sum2--;
            if(sum2 < 0 && f2 == 0) {
                f2 = 1;
                ans2++;
            }
        }
    }
    cout << min(ans1,ans2) << endl;
}
0