結果

問題 No.193 筒の数式
ユーザー 0w10w1
提出日時 2016-11-25 00:18:19
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 1,000 ms
コード長 991 bytes
コンパイル時間 1,730 ms
コンパイル使用メモリ 172,628 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-05-05 13:10:06
合計ジャッジ時間 2,437 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

int evaluate( const string &s ){
  if( not ( '0' <= s[ 0 ] and s[ 0 ] <= '9' ) )
    return -0x3f3f3f3f;
  if( not ( '0' <= s.back() and s.back() <= '9' ) )
    return -0x3f3f3f3f;
  vector< int > val;
  vector< char > op;
  for( int i = 0; i < s.size(); ++i ){
    if( not ( '0' <= s[ i ] and s[ i ] <= '9' ) )
      op.emplace_back( s[ i ] );
    else{
      int v = 0;
      int j;
      for( j = i; j < s.size(); ++j ){
        if( not ( '0' <= s[ j ] and s[ j ] <= '9' ) )
          break;
        v = v * 10 + s[ j ] - '0';
      }
      val.emplace_back( v );
      i = j - 1;
    }
  }
  int res = val[ 0 ];
  for( int i = 1; i < val.size(); ++i )
    res += ( op[ i - 1 ] == '+' ? 1 : -1 ) * val[ i ];
  return res;
}

signed main(){
  string S; cin >> S;
  S = S + S;
  int ans = -0x3f3f3f3f;
  for( int i = 0; i < S.size() / 2; ++i )
    ans = max( ans, evaluate( S.substr( i, S.size() / 2 ) ) );
  cout << ans << endl;
  return 0;
}
0