結果
問題 |
No.2145 Segment +-
|
ユーザー |
![]() |
提出日時 | 2022-12-02 23:17:26 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,019 bytes |
コンパイル時間 | 1,957 ms |
コンパイル使用メモリ | 193,164 KB |
最終ジャッジ日時 | 2025-02-09 04:24:42 |
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 21 WA * 3 |
ソースコード
#include <bits/stdc++.h> using namespace std; using ll = long long; int main() { int n; string s; cin >> n >> s; char p = '+'; for (int i = 0; i < n; i++) { if (s[i] == '?') { if (p == '+') { s[i] = '+'; } } else { p = s[i]; } } p = '+'; for (int i = n - 1; i >= 0; i--) { if (s[i] == '?') { if (p == '+') { s[i] = '+'; } } else { p = s[i]; } } p = '+'; int x = 0, y = 0, z = 0, r = 0; s.push_back('+'); for (int i = 0; i <= n; i++) { if (s[i] == '+') { if (x < 0) { x += (z - x + y) * 2; r++; y = 0; z = 0; } x++; z = max(z, x); p = '+'; } else { if (s[i] == '-') x--; else x++, y++; p = '-'; } } cout << r << endl; return 0; }