結果

問題 No.2145 Segment +-
ユーザー kotatsugamekotatsugame
提出日時 2022-12-02 23:12:10
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 31 ms / 2,000 ms
コード長 331 bytes
コンパイル時間 737 ms
コンパイル使用メモリ 66,932 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-18 08:28:35
合計ジャッジ時間 1,548 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 1 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 1 ms
5,376 KB
testcase_07 AC 2 ms
5,376 KB
testcase_08 AC 2 ms
5,376 KB
testcase_09 AC 2 ms
5,376 KB
testcase_10 AC 31 ms
5,376 KB
testcase_11 AC 29 ms
5,376 KB
testcase_12 AC 2 ms
5,376 KB
testcase_13 AC 1 ms
5,376 KB
testcase_14 AC 2 ms
5,376 KB
testcase_15 AC 3 ms
5,376 KB
testcase_16 AC 2 ms
5,376 KB
testcase_17 AC 1 ms
5,376 KB
testcase_18 AC 2 ms
5,376 KB
testcase_19 AC 1 ms
5,376 KB
testcase_20 AC 19 ms
5,376 KB
testcase_21 AC 5 ms
5,376 KB
testcase_22 AC 2 ms
5,376 KB
testcase_23 AC 2 ms
5,376 KB
testcase_24 AC 19 ms
5,376 KB
testcase_25 AC 29 ms
5,376 KB
testcase_26 AC 30 ms
5,376 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp:6:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
    6 | main()
      | ^~~~

ソースコード

diff #

#include<iostream>
using namespace std;
int N;
string S;
int dp[60];
main()
{
	cin>>N>>S;
	for(char c:S)
	{
		for(int i=0;i<60;i++)dp[i]+=c=='?'?1:c=='+'?i%2==0?1:-1:i%2==1?1:-1;
		for(int i=1;i<60;i++)dp[i]=max(dp[i],dp[i-1]);
		for(int i=0;i<60;i++)if(dp[i]<0)dp[i]=-1e9;
	}
	int k=0;
	while(dp[k]<0)k++;
	cout<<(k+1)/2<<endl;
}
0