結果
| 問題 |
No.193 筒の数式
|
| コンテスト | |
| ユーザー |
maine_honzuki
|
| 提出日時 | 2020-12-14 14:25:14 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 2 ms / 1,000 ms |
| コード長 | 730 bytes |
| コンパイル時間 | 2,083 ms |
| コンパイル使用メモリ | 193,288 KB |
| 最終ジャッジ日時 | 2025-01-17 00:32:00 |
|
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 16 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9;
int f(string S) {
int sign = 1, ret = 0, now = 0;
bool flag = false;
S += '+';
for (auto& c : S) {
if (c == '+' || c == '-') {
if (!flag)
return -INF;
ret += now * sign;
now = 0;
sign = ((c == '+') ? 1 : -1);
flag = false;
} else {
now *= 10;
now += (c - '0');
flag = true;
}
}
return ret;
}
int main() {
string S;
cin >> S;
int N = S.length();
S += S;
int ans = -INF;
for (int i = 0; i < N; i++) {
ans = max(ans, f(S.substr(i, N)));
}
cout << ans << endl;
}
maine_honzuki