結果
問題 | No.193 筒の数式 |
ユーザー | Hydrogen332 |
提出日時 | 2024-11-04 01:14:09 |
言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 2 ms / 1,000 ms |
コード長 | 983 bytes |
コンパイル時間 | 3,186 ms |
コンパイル使用メモリ | 246,548 KB |
実行使用メモリ | 6,820 KB |
最終ジャッジ日時 | 2024-11-04 01:14:13 |
合計ジャッジ時間 | 4,385 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 16 |
ソースコード
#include <bits/stdc++.h> using namespace std; using ll = long long; #define rep(i, s, e) for (int i = (int)s; i < (int)e; ++i) #define all(a) (a).begin(),(a).end() int main() { cin.tie(nullptr); string S; cin >> S; int siz = S.size(); S += S; ll ans = LLONG_MIN; rep(i, 0, siz) { if (S[i] == '+' || S[i] == '-' || S[i + siz - 1] == '+' || S[i + siz - 1] == '-') continue; ll sign = 1; ll num = 0; ll res = 0; rep(j, i, i + siz) { if (S[j] == '+') { res += sign * num; sign = 1; num = 0; } else if (S[j] == '-') { res += sign * num; sign = -1; num = 0; } else { num *= 10; num += S[j] - '0'; } } res += sign * num; ans = max(res, ans); } cout << ans << '\n'; }