結果

問題 No.1552 Simple Dice Game
ユーザー inksamuraiinksamurai
提出日時 2021-06-18 23:52:36
言語 C++17(clang)
(17.0.6 + boost 1.83.0)
結果
AC  
実行時間 327 ms / 2,500 ms
コード長 2,156 bytes
コンパイル時間 2,233 ms
コンパイル使用メモリ 105,976 KB
実行使用メモリ 5,084 KB
最終ジャッジ日時 2023-09-05 00:29:49
合計ジャッジ時間 7,825 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
5,040 KB
testcase_01 AC 3 ms
5,032 KB
testcase_02 AC 4 ms
5,008 KB
testcase_03 AC 327 ms
5,048 KB
testcase_04 AC 4 ms
5,040 KB
testcase_05 AC 3 ms
5,004 KB
testcase_06 AC 3 ms
5,048 KB
testcase_07 AC 3 ms
5,024 KB
testcase_08 AC 4 ms
5,032 KB
testcase_09 AC 255 ms
5,036 KB
testcase_10 AC 295 ms
5,024 KB
testcase_11 AC 296 ms
5,032 KB
testcase_12 AC 89 ms
5,040 KB
testcase_13 AC 250 ms
5,036 KB
testcase_14 AC 145 ms
5,036 KB
testcase_15 AC 185 ms
5,036 KB
testcase_16 AC 29 ms
5,068 KB
testcase_17 AC 45 ms
5,052 KB
testcase_18 AC 230 ms
5,084 KB
testcase_19 AC 324 ms
5,060 KB
testcase_20 AC 326 ms
5,068 KB
testcase_21 AC 325 ms
5,040 KB
testcase_22 AC 323 ms
5,036 KB
testcase_23 AC 324 ms
5,028 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cmath>
#include <deque>
#include <algorithm>
#include <iterator>
#include <list>
#include <tuple>
#include <map>
#include <unordered_map>
#include <queue>
#include <set>
#include <unordered_set>
#include <stack>
#include <string>
#include <vector>
#include <fstream>
#include <iostream>
#include <functional>
#include <numeric>
#include <iomanip> 
#include <stdio.h>
//eolibraries
#define lnf 3999999999999999999
#define inf 999999999
#define fi first
#define se second
#define pb push_back
#define ll long long
#define ld long double
#define all(c) (c).begin(),(c).end()
#define sz(c) (int)(c).size()
#define make_unique(a) sort(all(a)),a.erase(unique(all(a)),a.end())
#define pii pair <int,int>
#define rep(i,n) for(int i = 0 ; i < n ; i++) 
#define drep(i,n) for(int i = n-1 ; i >= 0 ; i--)
#define crep(i,x,n) for(int i = x ; i < n ; i++)
#define vi vector <int> 
#define vec(...) vector<__VA_ARGS__>
#define fcin ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);
//eodefine
using namespace std;

const int max_n = 103002;
const ll mod = 998244353;

ll n,m;

ll binpow(ll a, ll b) {  
  a %= mod; ll res = 1; 
  while (b) { if (b%2) res = res * a % mod; a = a * a % mod; b /= 2; } 
  return res % mod;
}

ll fact[max_n],invfact[max_n];

void prefact() {
  fact[0]=fact[1]=1;
  invfact[1]=1;
  rep(i,max_n-3){
    if(i>1)fact[i] = fact[i-1]*i; fact[i] %= mod;
    if(i>1)invfact[i]=mod-invfact[mod%i]*(mod/i)%mod;
  }
}


ll sub(ll a , ll b){
  a%=mod; b%=mod;
  return (((a-b)%mod)+mod)%mod;
}
ll prod(ll a , ll b){
  a%=mod; b%=mod;
  return ((a*b)%mod);
}

ll add(ll a , ll b){
  a%=mod; b%=mod;
  return (a+b)%mod;
}
ll f(ll i){
	return (i*(i+1))/2;
}
int main(){
fcin;
prefact();

	cin>>n>>m;
	
	ll ans=0,g=0;

	drep(i,m+1){
		if(i==0)break;
		// ll k=()
		ll x=binpow((m-i+1),n-1);
		ll sum=f(m)-f(i-1);
		ll d = prod(x,prod(sum,n));
		d = sub(d,g);
		ans = sub(ans,prod(i,d));
		// cout<<d<<" ";
		g = add(g,d);
	}

	g=0;
	crep(i,1,m+1){
		ll x=binpow(i,n-1);
		ll sum=f(i);
		ll d=prod(x,prod(sum,n));
		d = sub(d,g);
		ans = add(ans,prod(i,d));
		g = add(g,d);
		// cout<<d<<" ";
	}

	cout<<ans<<"\n";

/*
*/
    return 0;   
}
0