結果

問題 No.193 筒の数式
ユーザー nanasilinanasili
提出日時 2015-07-03 17:26:23
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 2 ms / 1,000 ms
コード長 993 bytes
コンパイル時間 592 ms
コンパイル使用メモリ 86,360 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-22 05:58:44
合計ジャッジ時間 1,576 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <algorithm>
#include <vector>
#include <cfloat>
#include <string>
#include <cmath>
#include <set>
#include <cstdlib>
#include <map>
#include <ctime>
#include <iomanip>
#include <functional>
#include <deque>
#include <iostream>
#include <cstring>
#include <queue>
#include <cstdio>
#include <stack>
#include <climits>
#include <sys/time.h>
#include <cctype>

using namespace std;

typedef long long ll;

ll calc(string s) {
  for (int i = 1; i < s.size(); i++) {
    if (s[i] == '+') {
      return stol(s.substr(0, i))+calc(s.substr(i+1));
    }else if (s[i] == '-') {
      return stol(s.substr(0, i))+calc(s.substr(i));
    }
  }

  return stol(s);
}

bool is_kigou(char c) {
  return c == '+' || c == '-';
}

int main() {
  string s;
  cin >> s;
  int n = s.size();
  ll ans = -1e10;
  for (int i = 0; i < n; i++) {
    string t = s.substr(i)+s.substr(0, i);
    if (is_kigou(t[0]) || is_kigou(t[n-1])) continue;
    ans = max(ans, calc(t));
  }
  std::cout << ans << std::endl;
}
0