結果
| 問題 |
No.193 筒の数式
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2015-04-26 22:28:04 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 2 ms / 1,000 ms |
| コード長 | 854 bytes |
| コンパイル時間 | 513 ms |
| コンパイル使用メモリ | 63,236 KB |
| 実行使用メモリ | 6,944 KB |
| 最終ジャッジ日時 | 2024-07-05 02:59:56 |
| 合計ジャッジ時間 | 1,313 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 16 |
ソースコード
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <utility>
#include <string>
using namespace std;
int main() {
string s;
cin >> s;
int n = s.size();
vector<int> a(n, 0);
long long max_ans = -1e18;
for (int i = 0; i < n; i++) {
if (!isdigit(s[i]) || !isdigit(s[(n + i - 1) % n])) {
continue;
}
long long ans = 0, tmp = 0;
bool isAdd = true;
for (int j = 0; j < n; j++) {
int idx = (i + j) % n;
switch (s[idx]) {
case '+':
ans = isAdd ? ans + tmp : ans - tmp;
tmp = 0;
isAdd = true;
break;
case '-':
ans = isAdd ? ans + tmp : ans - tmp;
tmp = 0;
isAdd = false;
break;
default:
tmp = tmp * 10 + s[idx] - '0';
break;
}
}
ans = isAdd ? ans + tmp : ans - tmp;
max_ans = max(ans, max_ans);
}
cout << max_ans << endl;
return 0;
}