結果

問題 No.3308 One-time Changed Formula
コンテスト
ユーザー Cafe1942
提出日時 2025-10-23 21:36:29
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 6 ms / 2,000 ms
コード長 2,311 bytes
コンパイル時間 931 ms
コンパイル使用メモリ 112,400 KB
実行使用メモリ 7,720 KB
最終ジャッジ日時 2025-10-24 01:06:44
合計ジャッジ時間 1,691 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 15
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <iomanip>//小数点出力用
//cout << fixed << setprecision(10) << ans;
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <unordered_map>
using ll = long long;
using namespace std;
#define modPHash (ll)((1LL<<61)-1)
#define modP (ll)998244353
bool chkrng0idx(int pos, int sup) { return (0 <= pos && pos < sup); }
int clk4(int num) { return (num - 2) * (num % 2); }
void yn(bool tf) { cout << (tf ? "Yes\n" : "No\n"); }

#define off 1010000

struct CM { // 大小比較用の関数オブジェクトを定義することもできる
    bool operator()(const pair<pair<ll, ll>,int>& a, const pair<pair<ll, ll>, int>& b) const noexcept {
        if (a.first.first >= 0 && b.first.first >= 0) {
            if (a.first.first * b.first.second == a.first.second * b.first.first)return a.second < b.second;
            return a.first.first * b.first.second < a.first.second * b.first.first;
        }
        else if (a.first.first < 0 && b.first.first >= 0) {
            return 0;
        }
        else if (a.first.first >= 0 && b.first.first < 0) {
            return 1;
        }
        if (a.first.first * b.first.second == a.first.second * b.first.first)return a.second < b.second;
        return a.first.first * b.first.second > a.first.second * b.first.first;
    }
};

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int Q;
    cin >> Q;
    while(Q--) {
        int N;
        string S;
        cin >> N >> S;
        int ans = 0;
        bool minus = 0;
        for (int i = 0;i < N;i++) {
            if (S[i] == '+') {
                if (!minus) {
                    ans += 9;
                }
                minus = 0;
            }
            else if (S[i] == '-') {
                if (!minus) {
                    ans += 9;
                }
                minus = 1;
            }
            else if (S[i] == '*') {
                if (!minus) {
                    ans += 9;
                }
            }
            else {
                if (minus) {
                    ans += S[i] - 0x31;
                }
                else {
                    ans += 0x39 - S[i];
                }
            }
        }
        cout << ans << "\n";
    }
}
0