結果

問題 No.1696 Nonnil
ユーザー 👑 kmjpkmjp
提出日時 2021-10-08 00:23:28
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 1,595 bytes
コンパイル時間 2,217 ms
コンパイル使用メモリ 205,284 KB
実行使用メモリ 18,640 KB
最終ジャッジ日時 2023-09-30 09:09:57
合計ジャッジ時間 34,682 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 29 ms
11,568 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 14 ms
4,380 KB
testcase_09 AC 68 ms
7,952 KB
testcase_10 AC 138 ms
7,976 KB
testcase_11 AC 61 ms
6,168 KB
testcase_12 AC 106 ms
7,952 KB
testcase_13 AC 66 ms
6,108 KB
testcase_14 AC 1,795 ms
18,196 KB
testcase_15 AC 292 ms
8,184 KB
testcase_16 AC 2,309 ms
18,640 KB
testcase_17 AC 1,297 ms
18,024 KB
testcase_18 AC 804 ms
14,032 KB
testcase_19 AC 2 ms
4,376 KB
testcase_20 AC 2 ms
4,376 KB
testcase_21 AC 810 ms
15,900 KB
testcase_22 AC 1,134 ms
16,124 KB
testcase_23 AC 1,020 ms
16,000 KB
testcase_24 AC 997 ms
15,988 KB
testcase_25 AC 1,894 ms
18,068 KB
testcase_26 AC 1,406 ms
18,036 KB
testcase_27 AC 1,858 ms
18,628 KB
testcase_28 AC 1,305 ms
16,256 KB
testcase_29 AC 1,078 ms
17,988 KB
testcase_30 AC 785 ms
14,176 KB
testcase_31 AC 1,380 ms
17,920 KB
testcase_32 AC 1,498 ms
18,152 KB
testcase_33 AC 1,475 ms
16,224 KB
testcase_34 AC 939 ms
18,140 KB
testcase_35 AC 1,311 ms
17,996 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;
	FOR(y,K+1) {
		ll pat=0;
		FOR(x,1515) pat+=(dp[x][y][0]-dp[x][y][1]);
		(ret+=pat%mo*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