結果
問題 | No.988 N×Mマス計算(総和) |
ユーザー | Haar |
提出日時 | 2020-02-16 02:36:14 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 76 ms / 2,000 ms |
コード長 | 3,050 bytes |
コンパイル時間 | 1,756 ms |
コンパイル使用メモリ | 203,644 KB |
実行使用メモリ | 5,376 KB |
最終ジャッジ日時 | 2024-07-06 07:23:36 |
合計ジャッジ時間 | 2,997 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 1 ms
5,248 KB |
testcase_01 | AC | 1 ms
5,376 KB |
testcase_02 | AC | 2 ms
5,376 KB |
testcase_03 | AC | 2 ms
5,376 KB |
testcase_04 | AC | 2 ms
5,376 KB |
testcase_05 | AC | 1 ms
5,376 KB |
testcase_06 | AC | 2 ms
5,376 KB |
testcase_07 | AC | 2 ms
5,376 KB |
testcase_08 | AC | 1 ms
5,376 KB |
testcase_09 | AC | 2 ms
5,376 KB |
testcase_10 | AC | 21 ms
5,376 KB |
testcase_11 | AC | 33 ms
5,376 KB |
testcase_12 | AC | 54 ms
5,376 KB |
testcase_13 | AC | 26 ms
5,376 KB |
testcase_14 | AC | 24 ms
5,376 KB |
testcase_15 | AC | 22 ms
5,376 KB |
testcase_16 | AC | 44 ms
5,376 KB |
testcase_17 | AC | 55 ms
5,376 KB |
testcase_18 | AC | 30 ms
5,376 KB |
testcase_19 | AC | 52 ms
5,376 KB |
testcase_20 | AC | 76 ms
5,376 KB |
ソースコード
#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; }