結果
問題 | No.988 N×Mマス計算(総和) |
ユーザー |
|
提出日時 | 2020-02-16 02:36:14 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 118 ms / 2,000 ms |
コード長 | 3,050 bytes |
コンパイル時間 | 2,374 ms |
コンパイル使用メモリ | 195,716 KB |
最終ジャッジ日時 | 2025-01-09 00:51:55 |
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 19 |
ソースコード
#include <bits/stdc++.h> /** * @attention 使用前にstatic変数Mを設定する。 */ class RuntimeModInt{ public: static std::uint32_t M; std::uint64_t val; RuntimeModInt(): val(0){} RuntimeModInt(std::int64_t n){ if(n >= M) val = n % M; else if(n < 0) val = n % M + M; else val = n; } const auto operator+(const RuntimeModInt &a) const {return RuntimeModInt(val + a.val);} const auto operator-(const RuntimeModInt &a) const {return RuntimeModInt(val - a.val);} const auto operator*(const RuntimeModInt &a) const {return RuntimeModInt(val * a.val);} const auto operator/(const RuntimeModInt &a) const {return RuntimeModInt(val * a.inv().val);} const auto& operator=(const RuntimeModInt &a){val = a.val; return *this;} const auto& operator+=(const RuntimeModInt &a){if((val += a.val) >= M) val -= M; return *this;} const auto& operator-=(const RuntimeModInt &a){if(val < a.val) val += M; val -= a.val; return *this;} const auto& operator*=(const RuntimeModInt &a){(val *= a.val) %= M; return *this;} const auto& operator/=(const RuntimeModInt &a){(val *= a.inv().val) %= M; return *this;} const bool operator==(const RuntimeModInt &a) const {return val == a.val;} const bool operator!=(const RuntimeModInt &a) const {return val != a.val;} const static auto power(std::int64_t n, std::int64_t p){ RuntimeModInt ret = 1, e = n; for(; p; e *= e, p >>= 1) if(p & 1) ret *= e; return ret; } const auto power(std::int64_t p) const { RuntimeModInt ret = 1, e = val; for(; p; e *= e, p >>= 1) if(p & 1) ret *= e; return ret; } const RuntimeModInt inv() const { std::int64_t a = val, b = M, u = 1, v = 0; while(b){ std::int64_t t = a/b; a -= t*b; std::swap(a,b); u -= t*v; std::swap(u,v); } u %= M; if(u < 0) u += M; return u; } }; auto operator-(const RuntimeModInt &a){return RuntimeModInt(-a.val);} auto operator+(std::int64_t a, const RuntimeModInt &b){return RuntimeModInt(a) + b;} auto operator-(std::int64_t a, const RuntimeModInt &b){return RuntimeModInt(a) - b;} auto operator*(std::int64_t a, const RuntimeModInt &b){return RuntimeModInt(a) * b;} auto operator/(std::int64_t a, const RuntimeModInt &b){return RuntimeModInt(a) / b;} std::uint32_t RuntimeModInt::M; std::istream& operator>>(std::istream &is, RuntimeModInt &a){is >> a.val; return is;} std::ostream& operator<<(std::ostream &os, const RuntimeModInt &a){os << a.val; return os;} using mint = RuntimeModInt; int main(){ int N, M, K; std::cin >> N >> M >> K; mint::M = K; char op; std::cin >> op; std::vector<int64_t> A(N), B(M); for(int i = 0; i < M; ++i) std::cin >> B[i]; for(int i = 0; i < N; ++i) std::cin >> A[i]; mint ans = 0; if(op == '+'){ for(int i = 0; i < N; ++i) ans += A[i] * M; for(int i = 0; i < M; ++i) ans += B[i] * N; }else{ mint sb = std::accumulate(B.begin(), B.end(), 0LL); for(int i = 0; i < N; ++i) ans += A[i] * sb; } std::cout << ans << std::endl; return 0; }