結果
問題 | No.1552 Simple Dice Game |
ユーザー | ebi_fly |
提出日時 | 2021-06-18 22:08:04 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 493 ms / 2,500 ms |
コード長 | 6,461 bytes |
コンパイル時間 | 1,294 ms |
コンパイル使用メモリ | 136,016 KB |
実行使用メモリ | 5,376 KB |
最終ジャッジ日時 | 2024-06-22 20:31:01 |
合計ジャッジ時間 | 7,503 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
5,248 KB |
testcase_01 | AC | 1 ms
5,376 KB |
testcase_02 | AC | 2 ms
5,376 KB |
testcase_03 | AC | 481 ms
5,376 KB |
testcase_04 | AC | 2 ms
5,376 KB |
testcase_05 | AC | 2 ms
5,376 KB |
testcase_06 | AC | 1 ms
5,376 KB |
testcase_07 | AC | 1 ms
5,376 KB |
testcase_08 | AC | 2 ms
5,376 KB |
testcase_09 | AC | 374 ms
5,376 KB |
testcase_10 | AC | 444 ms
5,376 KB |
testcase_11 | AC | 448 ms
5,376 KB |
testcase_12 | AC | 134 ms
5,376 KB |
testcase_13 | AC | 384 ms
5,376 KB |
testcase_14 | AC | 220 ms
5,376 KB |
testcase_15 | AC | 280 ms
5,376 KB |
testcase_16 | AC | 40 ms
5,376 KB |
testcase_17 | AC | 63 ms
5,376 KB |
testcase_18 | AC | 341 ms
5,376 KB |
testcase_19 | AC | 491 ms
5,376 KB |
testcase_20 | AC | 493 ms
5,376 KB |
testcase_21 | AC | 492 ms
5,376 KB |
testcase_22 | AC | 491 ms
5,376 KB |
testcase_23 | AC | 490 ms
5,376 KB |
ソースコード
#include <iostream> #include <algorithm> #include <utility> #include <string> #include <vector> #include <set> #include <stack> #include <queue> #include <map> #include <math.h> #include <string.h> #include <iomanip> #include <numeric> #include <cstdlib> #include <cstdint> #include <cmath> #include <functional> #include <limits> #include <cassert> #include <bitset> #include <chrono> #include <random> #include <memory> /* macro */ #define rep(i, a, n) for (int i = (int)(a); i < (int)(n); i++) #define rrep(i, a, n) for (int i = ((int)(n-1)); i >= (int)(a); i--) #define Rep(i, a, n) for (i64 i = (i64)(a); i< (i64)(n); i++) #define RRep(i, a, n) for (i64 i = ((i64)(n-i64(1))); i>=(i64)(a); i--) #define all(v) (v).begin(),(v).end() #define rall(v) (v).rbegin(),(v).rend() /* macro end */ /* template */ namespace ebi { #ifdef LOCAL #define debug(...) \ std::cerr << "LINE: " << __LINE__ << " [" << #__VA_ARGS__ << "]:", \ debug_out(__VA_ARGS__) #else #define debug(...) #endif void debug_out() { std::cerr << std::endl; } template <typename Head, typename... Tail> void debug_out(Head h, Tail... t) { std::cerr << " " << h; if (sizeof...(t) > 0) std::cout << " :"; debug_out(t...); } template <typename T1, typename T2> std::ostream& operator<<(std::ostream& os, std::pair<T1, T2> pa) { return os << pa.first << " " << pa.second; } template <typename T> std::ostream& operator<<(std::ostream& os, std::vector<T> vec) { for (std::size_t i = 0; i < vec.size(); i++) os << vec[i] << (i + 1 == vec.size() ? "" : " "); return os; } using size_t = std::size_t; using i64 = long long; using u64 = unsigned long long; template<class T> void fill(std::vector<T> &v) { for(T &e: v) std::cin >> e; } template<class T> struct Edge { int to; T cost; Edge(int to, T cost) : to(to), cost(cost) { } }; template<class T> using Graph = std::vector<std::vector<Edge<T>>>; using graph = std::vector<std::vector<int>>; template <class T> inline bool chmin(T &a, T b) { if (a > b){ a = b; return true; } return false; } template <class T> inline bool chmax(T &a, T b) { if (a < b){ a = b; return true; } return false; } template <class T> T gcd(T a, T b){ if( b==0 ) return a; else return gcd(b, a%b); } template <class T> T lcm(T a, T b) { return (a*b)/gcd(a,b); } template<class T> T Pow(T x, i64 n) { T res = 1; while(n>0){ if(n&1) res = res *x; x = x*x; n>>=1; } return res; } template<class T> T scan() { T val; std::cin >> val; return val; } constexpr i64 LNF = std::numeric_limits<i64>::max()/4; constexpr int INF = std::numeric_limits<int>::max()/4; const long double PI = acos(-1); const std::vector<int> dy = {1,0,-1,0,1,1,-1,-1}; const std::vector<int> dx = {0,1,0,-1,1,-1,1,-1}; } /* template end */ /* author: noshi91 reference: https://noshi91.hatenablog.com/entry/2019/03/31/174006 noshi91のブログで公開されているmodintを元にinv(), pow()を追加したものです */ #include <cstdint> #include <iostream> namespace ebi { template<std::uint_fast64_t Modulus> class modint { using u64 = std::uint_fast64_t; public: u64 a; constexpr modint(const u64 x = 0) noexcept : a(x % Modulus) {} constexpr u64 &value() noexcept { return a; } constexpr u64 &val() noexcept { return a; } constexpr const u64 &value() const noexcept { return a; } constexpr modint operator+(const modint rhs) const noexcept { return modint(*this) += rhs; } constexpr modint operator-(const modint rhs) const noexcept { return modint(*this) -= rhs; } constexpr modint operator*(const modint rhs) const noexcept { return modint(*this) *= rhs; } constexpr modint operator/(const modint rhs) const noexcept { return modint(*this) /= rhs; } constexpr modint &operator+=(const modint rhs) noexcept { a += rhs.a; if (a >= Modulus) { a -= Modulus; } return *this; } constexpr modint &operator-=(const modint rhs) noexcept { if (a < rhs.a) { a += Modulus; } a -= rhs.a; return *this; } constexpr modint &operator*=(const modint rhs) noexcept { a = a * rhs.a % Modulus; return *this; } constexpr modint &operator/=(modint rhs) noexcept { u64 exp = Modulus - 2; while (exp) { if (exp % 2) { *this *= rhs; } rhs *= rhs; exp /= 2; } return *this; } constexpr modint operator-() const { return modint() - *this; } bool operator==(const u64 rhs) { return a == rhs; } bool operator!=(const u64 rhs) { return a != rhs; } constexpr modint& operator++() { a++; if( a == mod() ) a = 0; return *this; } constexpr modint& operator--() { if( a == 0 ) a = mod(); a--; return *this; } modint pow(u64 n) const noexcept { modint res = 1; modint x = a; while(n>0){ if(n&1) res *= x; x *= x; n >>=1; } return res; } modint inv() const { return pow(Modulus-2); } static u64 mod() { return Modulus; } }; using modint998244353 = modint<998244353>; using modint1000000007 = modint<1000000007>; template<std::uint_fast64_t Modulus> std::ostream& operator<<(std::ostream& os, modint<Modulus> a){ return os << a.val(); } } // namespace ebi namespace ebi { using mint = modint998244353; using ld = long double; void main_() { const i64 n = scan<i64>(), m = scan<i64>(); mint ans = 0; mint inv_two = mint(2).inv(); rep(i,1,m) { mint ret = 0; if(i == 1) { ret = mint(2).pow(n) - 2; } else { ret = mint(i+1).pow(n)-mint(i-1).pow(n) - mint(2)*(mint(i).pow(n) - mint(i-1).pow(n)); } mint tmp = mint(i+2)*mint(m-i) + mint(m-i)*mint(m-i-1); tmp *= inv_two; ans += mint(i)*ret*tmp*mint(n); } std::cout << ans << std::endl; } } int main() { std::cout << std::fixed << std::setprecision(15); std::cin.tie(nullptr); std::ios::sync_with_stdio(false); ebi::main_(); return 0; }