結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
4,380 KB
testcase_01 AC 5 ms
4,376 KB
testcase_02 AC 4 ms
4,376 KB
testcase_03 AC 16 ms
4,376 KB
testcase_04 AC 4 ms
4,380 KB
testcase_05 AC 5 ms
4,380 KB
testcase_06 AC 4 ms
4,380 KB
testcase_07 AC 5 ms
4,380 KB
testcase_08 AC 9 ms
4,380 KB
testcase_09 AC 38 ms
4,744 KB
testcase_10 AC 73 ms
5,396 KB
testcase_11 AC 43 ms
5,296 KB
testcase_12 AC 59 ms
5,148 KB
testcase_13 AC 39 ms
4,892 KB
testcase_14 AC 825 ms
9,500 KB
testcase_15 AC 148 ms
6,836 KB
testcase_16 AC 1,030 ms
10,256 KB
testcase_17 AC 610 ms
8,184 KB
testcase_18 AC 372 ms
7,856 KB
testcase_19 AC 4 ms
4,380 KB
testcase_20 AC 5 ms
4,380 KB
testcase_21 AC 397 ms
7,124 KB
testcase_22 AC 531 ms
8,464 KB
testcase_23 AC 476 ms
8,100 KB
testcase_24 AC 469 ms
8,204 KB
testcase_25 AC 867 ms
10,064 KB
testcase_26 AC 669 ms
8,656 KB
testcase_27 AC 857 ms
9,448 KB
testcase_28 AC 633 ms
9,260 KB
testcase_29 AC 515 ms
8,020 KB
testcase_30 AC 385 ms
7,464 KB
testcase_31 AC 665 ms
8,316 KB
testcase_32 AC 721 ms
8,464 KB
testcase_33 AC 685 ms
9,256 KB
testcase_34 AC 449 ms
7,624 KB
testcase_35 AC 615 ms
8,480 KB
testcase_36 AC 2,861 ms
26,560 KB
testcase_37 TLE -
testcase_38 AC 3,292 ms
23,484 KB
testcase_39 AC 2,134 ms
10,772 KB
testcase_40 AC 2,246 ms
15,236 KB
testcase_41 AC 265 ms
9,084 KB
testcase_42 AC 21 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) {
			if(dp[x][y][0]) (dp[r][y+r-max(l,x)][1]+=dp[x][y][0])%=mo;
			if(dp[x][y][1]) (dp[r][y+r-max(l,x)][0]+=dp[x][y][1])%=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