結果

問題 No.1092 modular arithmetic
ユーザー firiexpfiriexp
提出日時 2020-11-29 17:02:38
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 53 ms / 2,000 ms
コード長 1,912 bytes
コンパイル時間 959 ms
コンパイル使用メモリ 102,668 KB
実行使用メモリ 4,372 KB
最終ジャッジ日時 2023-10-11 02:29:01
合計ジャッジ時間 5,898 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 17 ms
4,356 KB
testcase_02 AC 2 ms
4,352 KB
testcase_03 AC 27 ms
4,352 KB
testcase_04 AC 22 ms
4,352 KB
testcase_05 AC 23 ms
4,352 KB
testcase_06 AC 17 ms
4,348 KB
testcase_07 AC 22 ms
4,348 KB
testcase_08 AC 25 ms
4,348 KB
testcase_09 AC 22 ms
4,348 KB
testcase_10 AC 19 ms
4,372 KB
testcase_11 AC 20 ms
4,352 KB
testcase_12 AC 17 ms
4,348 KB
testcase_13 AC 9 ms
4,352 KB
testcase_14 AC 11 ms
4,352 KB
testcase_15 AC 3 ms
4,352 KB
testcase_16 AC 8 ms
4,348 KB
testcase_17 AC 11 ms
4,352 KB
testcase_18 AC 27 ms
4,352 KB
testcase_19 AC 17 ms
4,348 KB
testcase_20 AC 28 ms
4,352 KB
testcase_21 AC 22 ms
4,348 KB
testcase_22 AC 26 ms
4,352 KB
testcase_23 AC 45 ms
4,352 KB
testcase_24 AC 15 ms
4,368 KB
testcase_25 AC 34 ms
4,348 KB
testcase_26 AC 42 ms
4,352 KB
testcase_27 AC 8 ms
4,352 KB
testcase_28 AC 34 ms
4,352 KB
testcase_29 AC 53 ms
4,352 KB
testcase_30 AC 35 ms
4,372 KB
testcase_31 AC 6 ms
4,352 KB
testcase_32 AC 31 ms
4,352 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <cmath>

static const int MOD = 1000000007;
using ll = long long;
using u32 = unsigned;
using u64 = unsigned long long;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max() / 32 * 15 + 208;

class modint {
    static u32 &mod() { static u32 mod_ = 0; return mod_; }
public:
    u32 val;
    modint(const u32 x = 0) : val(x % M()) {}
    u32 &value() noexcept { return val; }
    const u32 &value() const noexcept { return val; }
    modint operator+(const modint b) const { return modint(*this) += b; }
    modint operator-(const modint b) const { return modint(*this) -= b; }
    modint operator*(const modint b) const { return modint(*this) *= b; }
    modint operator/(const modint b) const { return modint(*this) /= b; }
    modint &operator+=(const modint b) { val += b.val; if (val >= M()) val -= M(); return *this; }
    modint &operator-=(const modint b) { if (val < b.val) val += M(); val -= b.val; return *this; }
    modint &operator*=(const modint b) { val = (u64)val * b.val % M(); return *this; }
    modint pow(ll n) const { modint x = *this, r = 1; while(n){ if(n&1) r *= x; x *= x; n >>= 1; } return r; }
    modint &operator/=(modint b) { return *this *= b.pow(M()-2); }
    static void set_mod(const u32 x) { mod() = x; }
    static int M() { return mod(); }
};
using mint = modint;

int main() {
    int p, n;
    cin >> p >> n;
    mint::set_mod(p);
    vector<int> a(n);
    for (auto &&i : a) scanf("%d", &i);
    mint ans = a[0];
    string s;
    cin >> s;
    for (int i = 0; i+1 < n; ++i) {
        mint b = a[i+1];
        if(s[i] == '+') ans += b;
        if(s[i] == '-') ans -= b;
        if(s[i] == '*') ans *= b;
        if(s[i] == '/') ans /= b;
    }
    cout << ans.val << "\n";
    return 0;
}
0