結果

問題 No.2145 Segment +-
ユーザー 👑 rin204
提出日時 2022-12-02 23:34:35
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 1,562 bytes
コンパイル時間 1,736 ms
コンパイル使用メモリ 194,260 KB
最終ジャッジ日時 2025-02-09 04:29:11
ジャッジサーバーID
(参考情報)
judge3 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 23 WA * 1
権限があれば一括ダウンロードができます

ソースコード

diff #
プレゼンテーションモードにする

#include<bits/stdc++.h>
using namespace std;
using ll = long long;
const ll MOD = 998244353;
const int N = 1000100;
ll fac[N], invfac[N];
ll modpow(ll a, ll b, ll MOD){
ll ret = 1;
while (b > 0){
if(b & 1){
ret *= a;
ret %= MOD;
}
a *= a;
a %= MOD;
b >>= 1;
}
return ret;
}
void init(){
fac[0] = 1;
for(int i = 1; i < N; i++) fac[i] = fac[i - 1] * i % MOD;
invfac[N - 1] = modpow(fac[N - 1], MOD - 2, MOD);
for(int i = N - 2; i >= 0; i--) invfac[i] = invfac[i + 1] * (i + 1) % MOD;
}
ll nCk(int n, int k){
if(k < 0 || k > n) return 0;
else return (fac[n] * invfac[k] % MOD) * invfac[n - k] % MOD;
}
// ++++-?-?-?-?+------+++++++------------------------
void solve(){
int n;
string S;
cin >> n >> S;
int tot = 0;
int ma = 0;
int mi = 0;
int mic = 0;
int cnt = 0;
int ans = 0;
int prow = 0;
int cmax = 0;
bool rev = false;
for(auto s:S){
if(s == '+'){
tot++;
prow++;
if(tot > ma){
if(rev){
tot += cnt - mic;
tot += 2 * (ma - mi);
cnt = 0;
}
ma = tot;
cnt = cnt;
rev = false;
mic = cnt;
}
}
else if(s == '-'){
prow = 0;
tot--;
if(tot < 0){
if(!rev){
ans++;
rev = true;
tot -= cnt;
mi = tot;
mic = cnt;
}
else if(tot < mi){
int d1 = mi - tot;
int d2 = cnt - mic;
if(d1 > d2){
mi = tot;
mic = cnt;
}
}
}
}
else{
prow = 0;
cnt += 2;
if(rev){
tot--;
}
else{
tot++;
cmax = max(cmax, tot);
}
}
}
cout << ans << endl;
}
int main(){
solve();
}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
0