結果

問題 No.193 筒の数式
ユーザー kotatsugamekotatsugame
提出日時 2017-10-27 16:56:39
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 1,000 ms
コード長 437 bytes
コンパイル時間 646 ms
コンパイル使用メモリ 66,176 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-05-01 15:46:05
合計ジャッジ時間 1,401 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 2 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 2 ms
5,376 KB
testcase_11 AC 2 ms
5,376 KB
testcase_12 AC 2 ms
5,376 KB
testcase_13 AC 2 ms
5,376 KB
testcase_14 AC 2 ms
5,376 KB
testcase_15 AC 2 ms
5,376 KB
testcase_16 AC 2 ms
5,376 KB
testcase_17 AC 2 ms
5,376 KB
testcase_18 AC 2 ms
5,376 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp:20:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   20 | main()
      | ^~~~

ソースコード

diff #

#include <iostream>
using namespace std;
int f(string s)
{
	if(s[0]<48||s[s.size()-1]<48)return -1e9;
	int ans=0,now=0,f=1;
	for(int i=0;i<s.size();i++)
	{
		if(s[i]<48)
		{
			ans+=f?now:-now;
			now=0;
			f=s[i]=='+';
		}
		else now=now*10+s[i]-48;
	}
	ans+=f?now:-now;
	return ans;
}
main()
{
	string s;cin>>s;int m=-1e9,a;
	for(int i=0;i<s.size();i++)
	{
		a=f(s.substr(i,s.size()-i)+s.substr(0,i));
		m=m<a?a:m;
	}
	cout<<m<<endl;
}
0