結果

問題 No.193 筒の数式
コンテスト
ユーザー takayuta1999
提出日時 2015-04-26 22:22:21
言語 C++11
(gcc 15.2.0 + boost 1.89.0)
コンパイル:
g++-15 -O2 -lm -std=gnu++11 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 1 ms / 1,000 ms
コード長 847 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 479 ms
コンパイル使用メモリ 62,124 KB
実行使用メモリ 6,272 KB
最終ジャッジ日時 2026-03-26 09:42:31
合計ジャッジ時間 1,079 ms
ジャッジサーバーID
(参考情報)
judge3_0 / judge1_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 16
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <cstring>
#define SIZE 12
#define INF 1000000000000LL

using namespace std;
typedef long long int ll;

char str[SIZE];

int main()
{
	scanf("%s",&str);
	int n=strlen(str);
	ll ret=-INF;
	for(int i=0;i<n;i++)
	{
		if(str[i]=='-'||str[i]=='+') continue;
		if(str[(i+n-1)%n]=='-'||str[(i+n-1)%n]=='+') continue;
		ll calc=0;
		int now=i;
		while(str[now]!='-'&&str[now]!='+')
		{
			calc*=10LL;
			calc+=str[now]-'0';
			now=(now+1)%n;
			if(now==i) break;
		}
		while(now!=i)
		{
			bool up=str[now]=='+';
			now=(now+1)%n;
			ll vl=0;
			while(str[now]!='-'&&str[now]!='+')
			{
				vl*=10LL;
				vl+=str[now]-'0';
				now=(now+1)%n;
				if(now==i) break;
			}
			if(up) calc+=vl;
			else calc-=vl;
		}
		ret=max(ret,calc);
	}
	printf("%lld\n",ret);
	return 0;
}
0