結果

問題 No.1696 Nonnil
ユーザー 👑 kmjpkmjp
提出日時 2021-10-08 00:20:03
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 1,638 bytes
コンパイル時間 2,150 ms
コンパイル使用メモリ 204,512 KB
実行使用メモリ 18,832 KB
最終ジャッジ日時 2023-09-30 09:09:19
合計ジャッジ時間 35,696 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 6 ms
4,380 KB
testcase_01 AC 6 ms
4,380 KB
testcase_02 AC 5 ms
4,380 KB
testcase_03 AC 28 ms
11,648 KB
testcase_04 AC 5 ms
4,376 KB
testcase_05 AC 5 ms
4,380 KB
testcase_06 AC 5 ms
4,380 KB
testcase_07 AC 5 ms
4,380 KB
testcase_08 AC 13 ms
4,380 KB
testcase_09 AC 71 ms
8,264 KB
testcase_10 AC 141 ms
8,144 KB
testcase_11 AC 64 ms
6,312 KB
testcase_12 AC 109 ms
7,972 KB
testcase_13 AC 68 ms
6,272 KB
testcase_14 AC 1,852 ms
18,196 KB
testcase_15 AC 297 ms
8,248 KB
testcase_16 AC 2,338 ms
18,832 KB
testcase_17 AC 1,336 ms
17,984 KB
testcase_18 AC 826 ms
14,276 KB
testcase_19 AC 5 ms
4,376 KB
testcase_20 AC 5 ms
4,380 KB
testcase_21 AC 837 ms
15,924 KB
testcase_22 AC 1,178 ms
16,012 KB
testcase_23 AC 1,054 ms
16,072 KB
testcase_24 AC 1,038 ms
16,032 KB
testcase_25 AC 1,980 ms
18,116 KB
testcase_26 AC 1,457 ms
18,320 KB
testcase_27 AC 1,934 ms
18,544 KB
testcase_28 AC 1,370 ms
16,092 KB
testcase_29 AC 1,120 ms
17,992 KB
testcase_30 AC 831 ms
13,960 KB
testcase_31 AC 1,430 ms
17,964 KB
testcase_32 AC 1,556 ms
18,196 KB
testcase_33 AC 1,535 ms
16,048 KB
testcase_34 AC 968 ms
17,968 KB
testcase_35 AC 1,366 ms
18,344 KB
testcase_36 TLE -
testcase_37 -- -
testcase_38 -- -
testcase_39 -- -
testcase_40 -- -
testcase_41 -- -
testcase_42 -- -
権限があれば一括ダウンロードができます

ソースコード

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];
int dp[1517][1517][2];
const int 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