結果
問題 | No.2060 AND Sequence |
ユーザー | shauuebbit |
提出日時 | 2022-09-05 23:10:43 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 2 ms / 2,000 ms |
コード長 | 3,546 bytes |
コンパイル時間 | 2,403 ms |
コンパイル使用メモリ | 205,332 KB |
実行使用メモリ | 6,948 KB |
最終ジャッジ日時 | 2024-05-01 00:56:29 |
合計ジャッジ時間 | 4,218 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
6,816 KB |
testcase_01 | AC | 2 ms
6,816 KB |
testcase_02 | AC | 2 ms
6,940 KB |
testcase_03 | AC | 2 ms
6,944 KB |
testcase_04 | AC | 2 ms
6,940 KB |
testcase_05 | AC | 2 ms
6,944 KB |
testcase_06 | AC | 2 ms
6,940 KB |
testcase_07 | AC | 2 ms
6,944 KB |
testcase_08 | AC | 2 ms
6,944 KB |
testcase_09 | AC | 2 ms
6,940 KB |
testcase_10 | AC | 2 ms
6,940 KB |
testcase_11 | AC | 2 ms
6,940 KB |
testcase_12 | AC | 2 ms
6,940 KB |
testcase_13 | AC | 2 ms
6,944 KB |
testcase_14 | AC | 2 ms
6,940 KB |
testcase_15 | AC | 2 ms
6,940 KB |
testcase_16 | AC | 2 ms
6,944 KB |
testcase_17 | AC | 2 ms
6,940 KB |
testcase_18 | AC | 2 ms
6,944 KB |
testcase_19 | AC | 2 ms
6,940 KB |
testcase_20 | AC | 2 ms
6,944 KB |
testcase_21 | AC | 2 ms
6,940 KB |
testcase_22 | AC | 2 ms
6,948 KB |
testcase_23 | AC | 2 ms
6,944 KB |
testcase_24 | AC | 2 ms
6,944 KB |
testcase_25 | AC | 2 ms
6,940 KB |
testcase_26 | AC | 2 ms
6,940 KB |
testcase_27 | AC | 2 ms
6,944 KB |
testcase_28 | AC | 2 ms
6,940 KB |
testcase_29 | AC | 2 ms
6,944 KB |
testcase_30 | AC | 2 ms
6,944 KB |
testcase_31 | AC | 2 ms
6,940 KB |
testcase_32 | AC | 2 ms
6,940 KB |
testcase_33 | AC | 2 ms
6,944 KB |
testcase_34 | AC | 2 ms
6,940 KB |
testcase_35 | AC | 2 ms
6,944 KB |
testcase_36 | AC | 2 ms
6,944 KB |
testcase_37 | AC | 2 ms
6,944 KB |
testcase_38 | AC | 2 ms
6,940 KB |
testcase_39 | AC | 2 ms
6,940 KB |
testcase_40 | AC | 2 ms
6,940 KB |
testcase_41 | AC | 2 ms
6,944 KB |
testcase_42 | AC | 2 ms
6,940 KB |
testcase_43 | AC | 2 ms
6,944 KB |
testcase_44 | AC | 2 ms
6,940 KB |
testcase_45 | AC | 2 ms
6,944 KB |
ソースコード
#include <bits/stdc++.h> template <long long mod> class ModInt { private: long long number; public: constexpr ModInt(const ModInt& x) : number(x.number) {} constexpr ModInt(const long long number = 0) : number(number) { if (number < 0 || number >= mod) this->number %= mod; if (this->number < 0) this->number += mod; } constexpr long long get() const { return number; } constexpr ModInt& operator=(const ModInt& rhs) & { number = rhs.number; return *this; } constexpr ModInt operator+() const { return ModInt(*this); } constexpr ModInt operator-() const { return ModInt(mod - number); } constexpr ModInt& operator+=(const ModInt& rhs) { number += rhs.number; if (number >= mod) number -= mod; return *this; } constexpr ModInt& operator-=(const ModInt& rhs) { number -= rhs.number; if (number < 0) number += mod; return *this; } constexpr ModInt& operator*=(const ModInt& rhs) { number *= rhs.number; if (number >= mod) number %= mod; return *this; } constexpr ModInt& operator/=(const ModInt& rhs) { (*this) *= rhs.inverse(); return *this; } constexpr ModInt inverse() const { long long a = number, m = mod, u = 1, v = 0; while (m) { long long t = a / m; a -= t * m; u -= t * v; a ^= m; m ^= a; a ^= m; u ^= v; v ^= u; u ^= v; } return ModInt(u); } constexpr ModInt& operator++() { return *this += 1; } constexpr ModInt& operator--() { return *this -= 1; } constexpr ModInt operator++(int) { ModInt ret = *this; ++(*this); return ret; } constexpr ModInt operator--(int) { ModInt ret = *this; --(*this); return ret; } constexpr ModInt operator+(const ModInt& rhs) const { return ModInt(*this) += rhs; } constexpr ModInt operator-(const ModInt& rhs) const { return ModInt(*this) -= rhs; } constexpr ModInt operator*(const ModInt& rhs) const { return ModInt(*this) *= rhs; } constexpr ModInt operator/(const ModInt& rhs) const { return ModInt(*this) /= rhs; } constexpr ModInt operator^(const long long& rhs) const { long long b = number, e = rhs, y = 1, m = mod; bool inv = e < 0; if (inv) e = -e; while (e) { if (e & 1) (y *= b) %= m; (b *= b) %= m; e >>= 1; } return (inv ? ModInt(y).inverse() : ModInt(y)); } }; template <long long mod> std::istream& operator>>(std::istream& is, ModInt<mod>& x) { long long in; is >> in; x = in; return is; } template <long long mod> std::ostream& operator<<(std::ostream& os, const ModInt<mod>& x) { os << x.get(); return os; } constexpr int MOD = 998244353; constexpr int LEN = 30; using namespace std; using mint = ModInt<MOD>; int main() { int N, M; cin >> N >> M; vector dp(LEN + 1, vector<mint>(2, 0)); dp[0][0] = 1; for (int k = 0; k < LEN; k++) { if ((M >> (LEN - k - 1)) & 1) { dp[k + 1][1] += dp[k][1] * (N + 1); dp[k + 1][1] += dp[k][0]; dp[k + 1][0] += dp[k][0] * N; } else { dp[k + 1][1] += dp[k][1] * (N + 1); dp[k + 1][0] += dp[k][0]; } } cout << dp[LEN][0] + dp[LEN][1] << endl; return 0; }