結果
| 問題 |
No.2145 Segment +-
|
| コンテスト | |
| ユーザー |
Nachia
|
| 提出日時 | 2022-12-02 21:46:42 |
| 言語 | C++17(gcc12) (gcc 12.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 928 bytes |
| コンパイル時間 | 2,483 ms |
| コンパイル使用メモリ | 110,556 KB |
| 最終ジャッジ日時 | 2025-02-09 03:43:09 |
|
ジャッジサーバーID (参考情報) |
judge5 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 14 WA * 10 |
ソースコード
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <set>
#include <utility>
using namespace std;
using i32 = int32_t;
using u32 = uint32_t;
using i64 = int64_t;
using u64 = uint64_t;
#define rep(i,n) for(int i=0; i<(int)(n); i++)
const i64 INF = 1001001001001001001;
int main(){
int N;
string S;
cin >> N >> S;
int v = 0, hi = 0, rev = 1;
int ans = 0;
for(char c : S){
int dx = 0;
if(c == '-') dx = -1;
if(c == '+') dx = 1;
dx *= rev;
if(c == '?') dx = 1;
v += dx;
hi = max(hi, v);
if(v < 0){
ans++;
v = hi*2 + 1;
rev *= -1;
}
}
ans = (ans + 1) / 2;
cout << ans << '\n';
return 0;
}
struct ios_do_not_sync{
ios_do_not_sync(){
std::ios::sync_with_stdio(false);
std::cin.tie(nullptr);
}
} ios_do_not_sync_instance;
Nachia