QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#73998 | #3161. Another Coin Weighing Puzzle | UCSC_Ravioli# | ML | 2ms | 3336kb | C++20 | 885b | 2023-01-30 08:04:46 | 2023-01-30 08:04:47 |
Judging History
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<vector<ll>> dp(m+1, vector<ll>(m+1));
vector<ll> largest(k, 1);
dp[0][0] = 1;
ll x = 1;
for(int i=1; i<=m; i++){
x = x*k%mod;
dp[0][i] = x;
for(int i=1; i<k; i++) dp[0][i] -= largest[i];
dp[0][i] = (dp[0][i]%mod+mod)%mod;
vector<ll> newlargest(k);
for(int i=1; i<k; i++){
for(int j=1; j<=i; j++){
newlargest[i] += largest[j];
newlargest[i] %= mod;
}
}
swap(largest, newlargest);
}
for(int i=1; i<=m; i++){
for(int j=0; j<m; j++){
dp[i][j] = dp[i-1][j] + 2*dp[i-1][j+1];
dp[i][j] %= mod;
// cout << i << " weighings, bits = " << j << ": " << dp[i][j] << endl;
}
}
cout << dp[m][0] << endl;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 2ms
memory: 3308kb
input:
2 1
output:
9
result:
ok single line: '9'
Test #2:
score: 0
Accepted
time: 1ms
memory: 3336kb
input:
2 2
output:
17
result:
ok single line: '17'
Test #3:
score: -100
Memory Limit Exceeded
input:
10000 10000