結果

問題 No.1696 Nonnil
ユーザー 👑 kmjpkmjp
提出日時 2021-10-08 00:18:52
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 3,174 ms / 3,500 ms
コード長 1,636 bytes
コンパイル時間 2,361 ms
コンパイル使用メモリ 203,392 KB
実行使用メモリ 26,552 KB
最終ジャッジ日時 2023-09-30 09:08:42
合計ジャッジ時間 32,070 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 5 ms
4,376 KB
testcase_01 AC 5 ms
4,376 KB
testcase_02 AC 5 ms
4,380 KB
testcase_03 AC 20 ms
4,380 KB
testcase_04 AC 5 ms
4,376 KB
testcase_05 AC 5 ms
4,380 KB
testcase_06 AC 5 ms
4,376 KB
testcase_07 AC 5 ms
4,380 KB
testcase_08 AC 11 ms
4,376 KB
testcase_09 AC 40 ms
4,940 KB
testcase_10 AC 69 ms
5,544 KB
testcase_11 AC 39 ms
5,164 KB
testcase_12 AC 56 ms
5,484 KB
testcase_13 AC 33 ms
5,004 KB
testcase_14 AC 944 ms
11,368 KB
testcase_15 AC 133 ms
6,908 KB
testcase_16 AC 1,179 ms
12,532 KB
testcase_17 AC 718 ms
9,828 KB
testcase_18 AC 393 ms
8,744 KB
testcase_19 AC 5 ms
4,376 KB
testcase_20 AC 5 ms
4,376 KB
testcase_21 AC 461 ms
8,180 KB
testcase_22 AC 597 ms
9,548 KB
testcase_23 AC 543 ms
9,348 KB
testcase_24 AC 531 ms
9,360 KB
testcase_25 AC 988 ms
11,884 KB
testcase_26 AC 778 ms
10,152 KB
testcase_27 AC 1,016 ms
11,468 KB
testcase_28 AC 662 ms
10,676 KB
testcase_29 AC 593 ms
9,164 KB
testcase_30 AC 429 ms
8,552 KB
testcase_31 AC 779 ms
9,916 KB
testcase_32 AC 830 ms
10,188 KB
testcase_33 AC 737 ms
10,780 KB
testcase_34 AC 532 ms
8,608 KB
testcase_35 AC 703 ms
9,896 KB
testcase_36 AC 3,174 ms
26,552 KB
testcase_37 AC 2,858 ms
23,924 KB
testcase_38 AC 2,798 ms
23,544 KB
testcase_39 AC 2,700 ms
21,152 KB
testcase_40 AC 2,625 ms
23,656 KB
testcase_41 AC 300 ms
8,992 KB
testcase_42 AC 30 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef signed long long ll;

#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define FORR2(x,y,arr) for(auto& [x,y]:arr)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
template<class T> bool chmax(T &a, const T &b) { if(a<b){a=b;return 1;}return 0;}
template<class T> bool chmin(T &a, const T &b) { if(a>b){a=b;return 1;}return 0;}
//-------------------------------------------------------

int N,K;
int M;
int R[2020];
ll dp[1517][1517][2];
const ll mo=998244353;

ll modpow(ll a, ll n = mo-2) {
	ll r=1;a%=mo;
	while(n) r=r*((n%2)?a:1)%mo,a=a*a%mo,n>>=1;
	return r;
}
void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>N>>K;
	FOR(i,K) R[i]=K+1;
	cin>>M;
	FOR(i,M) {
		cin>>x>>y;
		R[x-1]=min(R[x-1],y);
	}
	vector<pair<int,int>> V;
	FOR(i,K) if(R[i]<K+1) {
		while(V.size()&&V.back().second>=R[i]) V.pop_back();
		V.push_back({i,R[i]});
	}
	dp[0][0][0]=1;
	FORR2(l,r,V) {
		FOR(x,r) FOR(y,r) {
			k=y+r-max(l,x);
			FOR(i,2) {
				dp[r][k][i]+=dp[x][y][i^1];
				if(dp[r][k][i]>=mo) dp[r][k][i]-=mo;
			}
		}
	}
	
	ll ret=0;
	ll sum=0;
	FOR(x,1515) FOR(y,1515) if(dp[x][y][0]||dp[x][y][1]) {
		(ret+=dp[x][y][0]*modpow(K-y,N))%=mo;
		(ret-=dp[x][y][1]*modpow(K-y,N))%=mo;
	}
	ret=(ret+mo)%mo;
	cout<<ret<<endl;
		
		
		
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}
0