結果
問題 | No.2457 Stampaholic (Easy) |
ユーザー | 沙耶花 |
提出日時 | 2023-09-02 21:37:50 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 1,768 ms / 4,000 ms |
コード長 | 2,631 bytes |
コンパイル時間 | 5,134 ms |
コンパイル使用メモリ | 277,632 KB |
実行使用メモリ | 4,372 KB |
最終ジャッジ日時 | 2023-09-02 21:38:10 |
合計ジャッジ時間 | 18,829 ms |
ジャッジサーバーID (参考情報) |
judge11 / judge15 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
4,368 KB |
testcase_01 | AC | 1 ms
4,372 KB |
testcase_02 | AC | 186 ms
4,368 KB |
testcase_03 | AC | 1 ms
4,372 KB |
testcase_04 | AC | 2 ms
4,372 KB |
testcase_05 | AC | 1,768 ms
4,368 KB |
testcase_06 | AC | 903 ms
4,372 KB |
testcase_07 | AC | 1 ms
4,372 KB |
testcase_08 | AC | 200 ms
4,372 KB |
testcase_09 | AC | 114 ms
4,368 KB |
testcase_10 | AC | 314 ms
4,372 KB |
testcase_11 | AC | 438 ms
4,372 KB |
testcase_12 | AC | 695 ms
4,368 KB |
testcase_13 | AC | 892 ms
4,368 KB |
testcase_14 | AC | 1,483 ms
4,368 KB |
testcase_15 | AC | 1,746 ms
4,372 KB |
testcase_16 | AC | 1,745 ms
4,368 KB |
testcase_17 | AC | 1,448 ms
4,368 KB |
testcase_18 | AC | 118 ms
4,368 KB |
testcase_19 | AC | 2 ms
4,368 KB |
testcase_20 | AC | 2 ms
4,372 KB |
testcase_21 | AC | 395 ms
4,368 KB |
ソースコード
#include <stdio.h> #include <atcoder/all> #include <bits/stdc++.h> using namespace std; using namespace atcoder; using mint = modint998244353; #define rep(i,n) for (int i = 0; i < (n); ++i) #define Inf32 1000000001 #define Inf64 4000000000000000001 template <class S, S (*op0)(S, S), S (*e0)(), S (*op1)(S, S), S (*e1)() > struct matrix{ vector<vector<S>> v; int _h,_w; matrix(vector<vector<S>> X){ v = X; _h = X.size(); _w = 0; if(X.size()>0)_w = X[0].size(); } matrix(int h,int w){ v.resize(h,vector<S>(w,e0())); _h = h; _w = w; } void add_element(int from,int to,S x){ v[to][from] = op0(v[to][from],x); } matrix e(){ assert(_h==_w); matrix<S,op0,e0,op1,e1> ret(_h,_w); for(int i=0;i<_h;i++){ for(int j=0;j<_w;j++){ if(i==j)ret.v[i][j] = e1(); else ret.v[i][j] = e0(); } } return ret; } matrix &operator*=(const matrix &another){ matrix<S,op0,e0,op1,e1> ret(_h,another._w); for(int i=0;i<_h;i++){ for(int j=0;j<another._w;j++){ ret.v[i][j] = e0(); for(int k=0;k<_w;k++){ ret.v[i][j] = op0(ret.v[i][j],op1(v[i][k],another.v[k][j])); } } } v = ret.v; return (*this); } matrix operator*(const matrix &another)const{ return (matrix(*this)*=another); } matrix pow(long long cnt){ matrix<S,op0,e0,op1,e1> ret = e(); auto temp = *this; while(cnt!=0LL){ if((cnt&1)==1){ ret *= temp; } temp *= temp; cnt>>=1; } return ret; } }; mint op0(mint a,mint b){ return a+b; } mint e0(){ return 0; } mint op1(mint a,mint b){ return a*b; } mint e1(){ return 1; } long long n; mint get(mint p){ //cout<<(p*4).val()<<endl; matrix<mint,op0,e0,op1,e1> M(2,2); rep(i,2){ rep(j,2){ if(i==j)M.add_element(i,j,1-p); else M.add_element(i,j,p); } } matrix<mint,op0,e0,op1,e1> t(2,1); t.v[0][0] = 1; M = M.pow(n) * t; return M.v[0][0]; } int main(){ long long h,w,k; cin>>h>>w>>n>>k; deque<pair<long long,long long>> x,y; rep(i,min(k,h-k+1)-1){ if(x.size()==h)break; x.emplace_back(i+1,1); if(x.size()==h)break; x.emplace_back(i+1,1); } if(x.size()<h)x.emplace_back(min(k,h-k+1),h-x.size()); rep(i,min(k,w-k+1)-1){ if(y.size()==w)break; y.emplace_back(i+1,1); if(y.size()==w)break; y.emplace_back(i+1,1); } if(y.size()<w)y.emplace_back(min(k,w-k+1),w-y.size()); mint ans = 0; rep(i,x.size()){ rep(j,y.size()){ mint p = x[i].first; p *= y[j].first; p /= h+1-k; p /= w+1-k; mint r = 1 - mint(1-p).pow(n); r *= x[i].second; r *= y[j].second; ans += r; } } cout<<ans.val()<<endl; return 0; }