結果

問題 No.193 筒の数式
ユーザー kpinkcatkpinkcat
提出日時 2023-11-05 17:22:25
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 1,000 ms
コード長 1,272 bytes
コンパイル時間 2,512 ms
コンパイル使用メモリ 209,596 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-11-05 17:22:29
合計ジャッジ時間 3,730 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
#include<iostream>
#include<iomanip>
#include<string>
#include<algorithm>
#include<vector>
#include<set>
#include<list>
#include<queue>
#include<math.h>
#include<bitset>
using ll = long long;
using namespace std;


int main(){
    string s;
    cin >> s;
    deque<string> dq1;
    for (int i = 0; i < s.size(); i++){
        string f, b;
        f = s.substr(0, i);
        b = s.substr(i);
        b += f;
        if (b[0] != '+' && b[0] != '-' && b[b.size()-1] != '+' && b[b.size()-1] != '-') dq1.push_back(b);
    }
    int ans = -1e9;
    while (!dq1.empty()) {
        string num = "";
        string ss = dq1.front();
        char op = '\0';
        int tmp = 0;
        for (int i = 0; i < ss.size(); i++){
            if (ss[i] >= '0' && ss[i] <= '9') num += ss[i];
            else {
                if (op == '\0' || op == '+') tmp += stoi(num);
                else tmp -= stoi(num);
                num = "";
                if (ss[i] == '+') op = '+';
                else op = '-';
            }
            if (i == ss.size() - 1){
                if (op == '+') tmp += stoi(num);
                else tmp -= stoi(num);
            }
        }
        ans = max(ans, tmp);
        dq1.pop_front();
    }
    cout << ans << endl;
}
0