QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#74000#3161. Another Coin Weighing PuzzleUCSC_Ravioli#TL 2ms3328kbC++20960b2023-01-30 08:10:482023-01-30 08:10:49

Judging History

你现在查看的是最新测评结果

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-01-30 08:10:49]
  • 评测
  • 测评结果:TL
  • 用时:2ms
  • 内存:3328kb
  • [2023-01-30 08:10:48]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define endl '\n'

int main(){
	ios::sync_with_stdio(false); cin.tie(0);
	int m, k;
	cin >> m >> k;
	
	const ll mod = 998244353;
	
	vector<ll> dp(m+1);
	vector<ll> largest(k, 1);
	dp[0] = 1;
	ll x = 1;
	for(int i=1; i<=m; i++){
		x = x*k%mod;
		dp[i] = x;
		for(int j=1; j<k; j++) dp[i] -= largest[j];
		dp[i] = (dp[i]%mod+mod)%mod;
		vector<ll> newlargest(k);
		for(int a=1; a<k; a++){
			for(int j=1; j<=a; j++){
				newlargest[a] += largest[j];
				newlargest[a] %= mod;
			}
		}
		swap(largest, newlargest);
	}
	
	// for(int i=0; i<=m; i++){
		// cout << dp[i] << ' ';
	// }
	// cout << endl;
	
	for(int i=1; i<=m; i++){
		vector<ll> ndp(m+1);
		for(int j=0; j<m; j++){
			ndp[j] = dp[j] + 2*dp[j+1];
			ndp[j] %= mod;
			// cout << i << " weighings, bits = " << j << ": " << dp[i][j] << endl;
		}
		swap(dp, ndp);
	}
	cout << dp[0] << endl;
}

詳細信息

Test #1:

score: 100
Accepted
time: 2ms
memory: 3328kb

input:

2 1

output:

9

result:

ok single line: '9'

Test #2:

score: 0
Accepted
time: 2ms
memory: 3280kb

input:

2 2

output:

17

result:

ok single line: '17'

Test #3:

score: -100
Time Limit Exceeded

input:

10000 10000

output:


result: