結果
| 問題 |
No.193 筒の数式
|
| コンテスト | |
| ユーザー |
kongarishisyamo
|
| 提出日時 | 2016-05-09 16:30:40 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 2 ms / 1,000 ms |
| コード長 | 1,102 bytes |
| コンパイル時間 | 471 ms |
| コンパイル使用メモリ | 58,760 KB |
| 実行使用メモリ | 6,820 KB |
| 最終ジャッジ日時 | 2024-10-05 13:07:31 |
| 合計ジャッジ時間 | 1,099 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 16 |
ソースコード
#include<iostream>
#include<string>
#include<cstdio>
using namespace std;
long long calc(string s){
if (s[0] == '-' || s[0] == '+' || s[s.size() - 1] == '-' || s[s.size() - 1] == '+') return -10000000000;
for (int i = 0; i < s.size() - 1; i++){
if (s[i] == '+' || s[i] == '-'){
if (s[i + 1] == '+' || s[i + 1] == '-') return -10000000000;
}
}
string c="";
int i;
for (i = 0;; i++){
if (s[i] == '+' || s[i] == '-') break;
else c += s[i];
}
long long ans = atol(c.c_str());
char e = s[i];
c = "";
for (; i < s.size(); i++){
if (s[i] == '+' || s[i] == '-'){
if (e == '+') ans += atol(c.c_str());
else ans -= atol(c.c_str());
c = "";
e = s[i];
}
else c += s[i];
}
if (e == '+') ans += atol(c.c_str());
else ans -= atol(c.c_str());
return ans;
}
int main(){
string s;
cin >> s;
long long ans = -10000000000;
string s2 = s;
while (1){
long long t = calc(s2);
if (t > ans) ans = t;
char tc = s2[s2.size() - 1];
for (int i = s2.size() - 1; i >= 1; i--){
s2[i] = s2[i - 1];
}
s2[0] = tc;
if (s == s2) break;
}
cout << ans << endl;
}
kongarishisyamo