結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
8,756 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 20 ms
11,692 KB
testcase_04 AC 2 ms
4,376 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 10 ms
4,380 KB
testcase_09 AC 49 ms
7,972 KB
testcase_10 AC 100 ms
8,008 KB
testcase_11 AC 43 ms
6,120 KB
testcase_12 AC 73 ms
7,920 KB
testcase_13 AC 46 ms
6,144 KB
testcase_14 AC 1,188 ms
18,080 KB
testcase_15 AC 216 ms
8,140 KB
testcase_16 AC 1,490 ms
18,636 KB
testcase_17 AC 841 ms
17,888 KB
testcase_18 AC 572 ms
14,048 KB
testcase_19 AC 2 ms
4,376 KB
testcase_20 AC 2 ms
4,376 KB
testcase_21 AC 510 ms
15,876 KB
testcase_22 AC 761 ms
15,960 KB
testcase_23 AC 672 ms
15,972 KB
testcase_24 AC 679 ms
15,988 KB
testcase_25 AC 1,296 ms
18,108 KB
testcase_26 AC 916 ms
18,016 KB
testcase_27 AC 1,193 ms
18,488 KB
testcase_28 AC 902 ms
16,300 KB
testcase_29 AC 699 ms
17,876 KB
testcase_30 AC 534 ms
13,908 KB
testcase_31 AC 882 ms
18,136 KB
testcase_32 AC 953 ms
18,148 KB
testcase_33 AC 996 ms
16,200 KB
testcase_34 AC 593 ms
17,980 KB
testcase_35 AC 855 ms
17,920 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,x+1) {
			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