結果
問題 | No.2145 Segment +- |
ユーザー | 沙耶花 |
提出日時 | 2022-12-02 23:10:39 |
言語 | C++17(gcc12) (gcc 12.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 552 ms / 2,000 ms |
コード長 | 1,014 bytes |
コンパイル時間 | 4,676 ms |
コンパイル使用メモリ | 261,880 KB |
実行使用メモリ | 5,248 KB |
最終ジャッジ日時 | 2024-10-10 01:39:15 |
合計ジャッジ時間 | 8,769 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 24 |
ソースコード
#include <stdio.h> #include <atcoder/all> #include <bits/stdc++.h> using namespace std; using namespace atcoder; using mint = modint998244353; #define rep(i,n) for (int i = 0; i < (n); ++i) #define Inf32 1000000001 #define Inf64 4000000000000000001 int main(){ int n; cin>>n; string s; cin>>s; vector dp(50,vector<int>(2,-Inf32)); dp[0][0] = 0; rep(i,n){ vector ndp(50,vector<int>(2,-Inf32)); rep(j,50){ rep(k,2){ if(dp[j][k]==-Inf32)continue; rep(l,2){ int nv = dp[j][k]; int nj = j; if(k==0&&l==1)nj++; if(nj>=50)continue; if(s[i]=='?')nv++; else{ if(s[i]=='+'){ if(l==0)nv++; else nv--; } else{ if(l==0)nv--; else nv++; } } if(nv<0)continue; //cout<<i<<','<<nj<<','<<nv<<endl; ndp[nj][l] = max(ndp[nj][l],nv); } } } swap(dp,ndp); } rep(i,50){ rep(j,2){ if(dp[i][j]!=-Inf32){ cout<<i<<endl; return 0; } } } return 0; }