結果

問題 No.193 筒の数式
ユーザー srup٩(๑`н´๑)۶srup٩(๑`н´๑)۶
提出日時 2016-09-17 01:11:07
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,055 bytes
コンパイル時間 534 ms
コンパイル使用メモリ 61,912 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-28 15:14:43
合計ジャッジ時間 1,254 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
5,248 KB
testcase_01 AC 1 ms
5,376 KB
testcase_02 AC 1 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 1 ms
5,376 KB
testcase_06 AC 1 ms
5,376 KB
testcase_07 AC 1 ms
5,376 KB
testcase_08 AC 1 ms
5,376 KB
testcase_09 AC 2 ms
5,376 KB
testcase_10 AC 2 ms
5,376 KB
testcase_11 AC 1 ms
5,376 KB
testcase_12 AC 1 ms
5,376 KB
testcase_13 AC 1 ms
5,376 KB
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0;i<(n);i++)

int main(void){
	string s; cin >> s;
	int n = s.size();
	s += s;//2倍に伸ばす

	int ans = 0;
	for (int l = 0; l < n; ++l){
		if(!('0' <= s[l] && s[l] <= '9' && '0' <= s[l + n - 1] && s[l + n - 1] <= '9')){
			continue;
		}
		int tl = l;
		vector<int> num, v;
		for (int r = l; r < l + n; ++r){
			if(!('0' <= s[r] && s[r] <= '9')){
				if(s[r] == '+') v.push_back(1);
				else if(s[r] == '-') v.push_back(0);
				
				string ss = s.substr(tl, r - tl);
				num.push_back(stoi(ss));
				tl = r + 1;//次に数字が出てくる位置
			}

			if(r == l + n - 1 && '0' <= s[r] && s[r] <= '9'){//最後
				string ss = s.substr(tl, r - tl + 1);
				num.push_back(stoi(ss));
			}
		}

		int sum = 0;
		rep(i, num.size()){
			if(i == 0){
				sum += num[i];	
			}else{
				if(v[i - 1] == 1) sum += num[i];
				else sum -= num[i];
			}
		}
		ans = max(ans, sum);
	}
	printf("%d\n", ans);
	return 0;
}
0