結果
| 問題 |
No.2145 Segment +-
|
| コンテスト | |
| ユーザー |
Nachia
|
| 提出日時 | 2024-04-21 16:42:49 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 5 ms / 2,000 ms |
| コード長 | 825 bytes |
| コンパイル時間 | 724 ms |
| コンパイル使用メモリ | 79,588 KB |
| 最終ジャッジ日時 | 2025-02-21 08:16:21 |
|
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 24 |
ソースコード
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <set>
#include <utility>
using namespace std;
#define rep(i,n) for(int i=0; i<(int)(n); i++)
int main(){
ios::sync_with_stdio(false); cin.tie(nullptr);
int N;
string S;
cin >> N >> S;
vector<int> sumQ = {0};
int v = 0, rev = 1, pos = 0;
int hi = 0;
int ans = 0;
for(char c : S){
int dx = 0;
sumQ.push_back(sumQ.back());
if(c == '-') dx = -1;
if(c == '+') dx = 1;
dx *= rev;
if(c == '?'){ dx = 1; hi++; }
v += dx;
hi = max(hi, v);
if(v < 0){
ans++;
v = hi*2 + 1;
rev *= -1;
hi = v;
}
pos++;
}
ans = (ans + 1) / 2;
cout << ans << '\n';
return 0;
}
Nachia