結果

問題 No.193 筒の数式
ユーザー kyuridenamida
提出日時 2015-04-26 22:15:16
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
AC  
実行時間 2 ms / 1,000 ms
コード長 968 bytes
コンパイル時間 1,520 ms
コンパイル使用メモリ 162,436 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-07-05 02:55:52
合計ジャッジ時間 2,237 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 16
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define int long long

signed main(){
	string s;
	int x;
	long long ans = -1e18;

	cin >> s;
	for(int w = 0 ; w < 2 ; w++){
		for(int i = 0 ; i < 2*s.size() ; i++){
			try{
				if( s[0] == '+' || s[0] == '-' ) throw "";
				if( s[s.size()-1] == '+' || s[s.size()-1] == '-' ) throw "";
				
				int r = 0;
				int now;
				
				for(int j = 0 ; j+1 < s.size() ; j++){
					if( s[j] == s[j+1] && (s[j] == '+'||s[j]=='-') ) throw "";
					
				}
				int p = 1;
				//cout << s << endl;
				
				string t = s;
				t += "~";
				for(int j = 0 ; j < t.size() ; ){
					int now = 0;
					int k = j;
					while( t[k] >= '0' && t[k] <= '9' )
						now = now * 10 + t[k++] - '0';
					r += p * now;
					if( t[k++] == '-' ) p = -1;
					else p = 1;
					j = k;
				}
				ans = max(ans,r);
			}catch(const char *msg){
				
			}
			rotate(s.begin(),s.begin()+1,s.end());
		}
		//reverse(s.begin(),s.end());
	}
	cout << ans << endl;
	
}
0