結果
問題 |
No.3210 Fixed Sign Sequense
|
ユーザー |
|
提出日時 | 2025-07-25 22:33:24 |
言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 34 ms / 2,000 ms |
コード長 | 845 bytes |
コンパイル時間 | 2,787 ms |
コンパイル使用メモリ | 275,908 KB |
実行使用メモリ | 31,928 KB |
最終ジャッジ日時 | 2025-07-25 22:33:33 |
合計ジャッジ時間 | 5,006 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 38 |
ソースコード
#include <bits/stdc++.h> using namespace std; #define int long long int #define endl "\n" int n; int fn(int i,int j,string &s,int dp[300005][2]){ if(i==n)return 0; if(dp[i][j] != -1)return dp[i][j]; int ans = fn(i+1,j,s,dp); if(j == 0){ if(s[i] == '+'){ ans = max(ans,1+fn(i+1,1,s,dp)); }else if(s[i] == '-'){ ans = max(ans,1+fn(i+1,0,s,dp)); }else if(s[i] == '0'){ ans = max(ans,1+fn(i+1,1,s,dp)); } }else if(j == 1){ if(s[i] == '+'){ ans = max(ans,1+fn(i+1,1,s,dp)); } } return dp[i][j] = ans; } signed main(){ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin>>n; string s;cin>>s; int dp[300005][2]; memset(dp,-1,sizeof(dp)); int ans = fn(0,0,s,dp); cout<<ans; return 0; }