結果

問題 No.2145 Segment +-
ユーザー merom686merom686
提出日時 2022-12-02 23:13:31
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 550 bytes
コンパイル時間 2,573 ms
コンパイル使用メモリ 194,676 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-04-18 08:29:48
合計ジャッジ時間 3,347 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

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

int main() {
    int n;
    string s;
    cin >> n >> s;

    char p = '+';
    int x = 0, y = 0, r = 0;
    s.push_back('+');
    for (int i = 0; i <= n; i++) {
        if (s[i] != '-') {
            if (x < 0) {
                x += (y - x) * 2;
                r++;
                y = 0;
            }
            x++;
            y = max(y, x);
            p = '+';
        } else {
            x--;
            p = '-';
        }
    }
    cout << r << endl;

    return 0;
}
0