提出 #66392700
ソースコード 拡げる
#include<bits/stdc++.h>
using namespace std;
#define all(a) a.begin(),a.end()
#define pb push_back
#define sz(a) ((int)a.size())
using ll=long long;
using u32=unsigned int;
using u64=unsigned long long;
using i128=__int128;
using u128=unsigned __int128;
using f128=__float128;
using pii=pair<int,int>;
using pll=pair<ll,ll>;
template<typename T> using vc=vector<T>;
template<typename T> using vvc=vc<vc<T>>;
template<typename T> using vvvc=vc<vvc<T>>;
using vi=vc<int>;
using vll=vc<ll>;
using vvi=vc<vi>;
using vvll=vc<vll>;
#define vv(type,name,n,...) \
vector<vector<type>> name(n,vector<type>(__VA_ARGS__))
#define vvv(type,name,n,m,...) \
vector<vector<vector<type>>> name(n,vector<vector<type>>(m,vector<type>(__VA_ARGS__)))
template<typename T> using min_heap=priority_queue<T,vector<T>,greater<T>>;
template<typename T> using max_heap=priority_queue<T>;
// https://trap.jp/post/1224/
#define rep1(n) for(ll i=0; i<(ll)(n); ++i)
#define rep2(i,n) for(ll i=0; i<(ll)(n); ++i)
#define rep3(i,a,b) for(ll i=(ll)(a); i<(ll)(b); ++i)
#define rep4(i,a,b,c) for(ll i=(ll)(a); i<(ll)(b); i+=(c))
#define cut4(a,b,c,d,e,...) e
#define rep(...) cut4(__VA_ARGS__,rep4,rep3,rep2,rep1)(__VA_ARGS__)
#define per1(n) for(ll i=((ll)n)-1; i>=0; --i)
#define per2(i,n) for(ll i=((ll)n)-1; i>=0; --i)
#define per3(i,a,b) for(ll i=((ll)a)-1; i>=(ll)(b); --i)
#define per4(i,a,b,c) for(ll i=((ll)a)-1; i>=(ll)(b); i-=(c))
#define per(...) cut4(__VA_ARGS__,per4,per3,per2,per1)(__VA_ARGS__)
#define rep_subset(i,s) for(ll i=(s); i>=0; i=(i==0?-1:(i-1)&(s)))
template<typename T, typename S> constexpr T ifloor(const T a, const S b){return a/b-(a%b&&(a^b)<0);}
template<typename T, typename S> constexpr T iceil(const T a, const S b){return ifloor(a+b-1,b);}
template<typename T>
void sort_unique(vector<T> &vec){
sort(vec.begin(),vec.end());
vec.resize(unique(vec.begin(),vec.end())-vec.begin());
}
template<typename T, typename S> constexpr bool chmin(T &a, const S b){if(a>b) return a=b,true; return false;}
template<typename T, typename S> constexpr bool chmax(T &a, const S b){if(a<b) return a=b,true; return false;}
template<typename T, typename S> istream& operator >> (istream& i, pair<T,S> &p){return i >> p.first >> p.second;}
template<typename T, typename S> ostream& operator << (ostream& o, const pair<T,S> &p){return o << p.first << ' ' << p.second;}
#ifdef i_am_noob
#define bug(...) cerr << "#" << __LINE__ << ' ' << #__VA_ARGS__ << "- ", _do(__VA_ARGS__)
template<typename T> void _do(vector<T> x){for(auto i: x) cerr << i << ' ';cerr << "\n";}
template<typename T> void _do(set<T> x){for(auto i: x) cerr << i << ' ';cerr << "\n";}
template<typename T> void _do(unordered_set<T> x){for(auto i: x) cerr << i << ' ';cerr << "\n";}
template<typename T> void _do(T && x) {cerr << x << endl;}
template<typename T, typename ...S> void _do(T && x, S&&...y) {cerr << x << ", "; _do(y...);}
#else
#define bug(...) 777771449
#endif
template<typename T> void print(vector<T> x){for(auto i: x) cout << i << ' ';cout << "\n";}
template<typename T> void print(set<T> x){for(auto i: x) cout << i << ' ';cout << "\n";}
template<typename T> void print(unordered_set<T> x){for(auto i: x) cout << i << ' ';cout << "\n";}
template<typename T> void print(T && x) {cout << x << "\n";}
template<typename T, typename... S> void print(T && x, S&&... y) {cout << x << ' ';print(y...);}
template<typename T> istream& operator >> (istream& i, vector<T> &vec){for(auto &x: vec) i >> x; return i;}
vvi read_graph(int n, int m, int base=1){
vvi adj(n);
for(int i=0,u,v; i<m; ++i){
cin >> u >> v,u-=base,v-=base;
adj[u].pb(v),adj[v].pb(u);
}
return adj;
}
vvi read_tree(int n, int base=1){return read_graph(n,n-1,base);}
template<typename T, typename S> pair<T,S> operator + (const pair<T,S> &a, const pair<T,S> &b){return {a.first+b.first,a.second+b.second};}
template<typename T> constexpr T inf=0;
template<> constexpr int inf<int> = 0x3f3f3f3f;
template<> constexpr ll inf<ll> = 0x3f3f3f3f3f3f3f3f;
template<typename T> vector<T> operator += (vector<T> &a, int val){for(auto &i: a) i+=val; return a;}
template<typename T> T isqrt(const T &x){T y=sqrt(x+2); while(y*y>x) y--; return y;}
#define ykh mt19937 rng(chrono::steady_clock::now().time_since_epoch().count())
#include<atcoder/all>
using namespace atcoder;
using mint=modint998244353;
//using mint=modint1000000007;
template<int mod>
struct nCr{
vector<static_modint<mod>> fac,inv,ifac;
void calc(int n){
fac.resize(n+1),inv.resize(n+1),ifac.resize(n+1);
fac[0]=inv[1]=ifac[0]=1;
for(int i=1; i<=n; ++i) fac[i]=fac[i-1]*static_modint<mod>::raw(i);
for(int i=2; i<=n; ++i) inv[i]=inv[mod%i]*static_modint<mod>::raw(mod-mod/i);
for(int i=1; i<=n; ++i) ifac[i]=ifac[i-1]*inv[i];
}
static_modint<mod> C(int n, int m){
if(m<0||m>n) return 0;
return fac[n]*ifac[m]*ifac[n-m];
}
};
nCr<998244353> de;
void ahcorz(){
de.calc(200005);
int n,m; cin >> n >> m;
if(n<m) swap(n,m);
vvv(mint,dp,n+1,m+1,2);
rep(m+1) dp[0][i][0]=1,dp[0][i][1]=0;
rep(i,1,n+1){
dp[i][0][0]=1,dp[i][0][1]=0;
rep(j,1,m+1){
rep(r,j){
mint tmp=r==0?j+1:de.C(j,r+1);
dp[i][j][0]+=dp[i-1][j-r][0]*tmp;
dp[i][j][1]+=dp[i-1][j-r][1]*tmp;
dp[i][j][1]+=dp[i-1][j-r][0]*tmp*r*i;
dp[i][j][1]+=dp[i-1][j-r][0]*(r==0?de.C(j+1,r+2):de.C(j,r+2));
}
}
}
print(dp[n][m][1].val());
}
signed main(){
ios_base::sync_with_stdio(0),cin.tie(0);
cout << fixed << setprecision(20);
int t=1;
//cin >> t;
while(t--) ahcorz();
}
提出情報
| 提出日時 |
|
| 問題 |
D - Limestone |
| ユーザ |
i_am_noob |
| 言語 |
C++ 23 (gcc 12.2) |
| 得点 |
1000 |
| コード長 |
5885 Byte |
| 結果 |
AC |
| 実行時間 |
573 ms |
| メモリ |
35104 KiB |
ジャッジ結果
| セット名 |
Sample |
All |
| 得点 / 配点 |
0 / 0 |
1000 / 1000 |
| 結果 |
|
|
| セット名 |
テストケース |
| Sample |
00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt |
| All |
00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt, 01_test_00.txt, 01_test_01.txt, 01_test_02.txt, 01_test_03.txt, 01_test_04.txt, 01_test_05.txt, 01_test_06.txt, 01_test_07.txt, 01_test_08.txt, 01_test_09.txt, 01_test_10.txt, 01_test_11.txt, 01_test_12.txt, 01_test_13.txt, 01_test_14.txt, 01_test_15.txt, 01_test_16.txt, 01_test_17.txt, 01_test_18.txt, 01_test_19.txt, 01_test_20.txt, 01_test_21.txt, 01_test_22.txt, 01_test_23.txt, 01_test_24.txt, 01_test_25.txt, 01_test_26.txt, 01_test_27.txt, 01_test_28.txt, 01_test_29.txt, 01_test_30.txt |
| ケース名 |
結果 |
実行時間 |
メモリ |
| 00_sample_00.txt |
AC |
4 ms |
5428 KiB |
| 00_sample_01.txt |
AC |
4 ms |
5392 KiB |
| 00_sample_02.txt |
AC |
50 ms |
8620 KiB |
| 01_test_00.txt |
AC |
18 ms |
18404 KiB |
| 01_test_01.txt |
AC |
20 ms |
19424 KiB |
| 01_test_02.txt |
AC |
26 ms |
18132 KiB |
| 01_test_03.txt |
AC |
30 ms |
15264 KiB |
| 01_test_04.txt |
AC |
48 ms |
15884 KiB |
| 01_test_05.txt |
AC |
114 ms |
15136 KiB |
| 01_test_06.txt |
AC |
183 ms |
14956 KiB |
| 01_test_07.txt |
AC |
415 ms |
15460 KiB |
| 01_test_08.txt |
AC |
260 ms |
15452 KiB |
| 01_test_09.txt |
AC |
85 ms |
14076 KiB |
| 01_test_10.txt |
AC |
89 ms |
16520 KiB |
| 01_test_11.txt |
AC |
43 ms |
16056 KiB |
| 01_test_12.txt |
AC |
26 ms |
15172 KiB |
| 01_test_13.txt |
AC |
17 ms |
16816 KiB |
| 01_test_14.txt |
AC |
18 ms |
19132 KiB |
| 01_test_15.txt |
AC |
17 ms |
21696 KiB |
| 01_test_16.txt |
AC |
26 ms |
31344 KiB |
| 01_test_17.txt |
AC |
552 ms |
16232 KiB |
| 01_test_18.txt |
AC |
559 ms |
16312 KiB |
| 01_test_19.txt |
AC |
547 ms |
16364 KiB |
| 01_test_20.txt |
AC |
555 ms |
16288 KiB |
| 01_test_21.txt |
AC |
552 ms |
16360 KiB |
| 01_test_22.txt |
AC |
550 ms |
16412 KiB |
| 01_test_23.txt |
AC |
552 ms |
16336 KiB |
| 01_test_24.txt |
AC |
567 ms |
16580 KiB |
| 01_test_25.txt |
AC |
559 ms |
16676 KiB |
| 01_test_26.txt |
AC |
555 ms |
16344 KiB |
| 01_test_27.txt |
AC |
4 ms |
5500 KiB |
| 01_test_28.txt |
AC |
30 ms |
35104 KiB |
| 01_test_29.txt |
AC |
29 ms |
34980 KiB |
| 01_test_30.txt |
AC |
573 ms |
16524 KiB |