結果

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

ソースコード

diff #

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

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    string s;
    cin >> n >> s;
    vector<int> a(n);
    int cur = 2;
    for(int i = 0; i < n; i++){
        if(s[i] == '+') a[i] = cur++;
    }
    cur = -2;
    for(int i = n - 1; i >= 0; i--){
        if(s[i] == '-') a[i] = cur--;
    }
    vector<int> b;
    for(int i = 0; i < n; i++){
        int p = lower_bound(b.begin(), b.end(), a[i]) - b.begin();
        if(p == b.size()) b.emplace_back(a[i]);
        else b[p] = a[i];
    }
    cout << b.size() << '\n';
}
0