QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#149655 | #6410. Classical DP Problem | Insert_Username_Here | WA | 1ms | 3672kb | C++20 | 1.1kb | 2023-08-25 07:27:11 | 2023-08-25 07:27:15 |
Judging History
answer
#include <bits/stdc++.h>
#define f first
#define s second
#define mp make_pair
using namespace std;
typedef long long ll;
const ll mod = 998244353;
// Cope Counter = at least 120
ll po(ll b, ll p) {
ll a = 1;
while(p > 0) {
if(p % 2 == 1) a = a * b % mod;
b = b * b % mod;
p /= 2;
}
return a;
}
signed main() {
ios::sync_with_stdio(0);
cin.tie(0);
ll n;
cin >> n;
ll fact[n + 1], inv[n + 1], arr[n + 1];
fact[0] = 1;
for(ll i = 1; i <= n; i++) fact[i] = fact[i - 1] * i % mod;
inv[n] = po(fact[n], mod - 2);
for(ll i = n - 1; i >= 0; i--) inv[i] = inv[i + 1] * (i + 1) % mod;
ll smax = 0;
arr[n] = 0;
for(ll i = n - 1; i >= 0; i--) {
cin >> arr[i];
smax = max(smax, min(i + 1, arr[i]));
}
ll ans = 0, cur, cols = arr[smax];
for(ll i = 0; i < cols; i++) {
cur = fact[cols] * inv[i] % mod * inv[cols - i] % mod;
for(ll j = 0; j < smax; j++) {
cur = cur * (arr[j] - i) % mod;
}
if(i & 1) ans = (ans - cur + mod) % mod;
else ans = (ans + cur) % mod;
}
cout << smax << " " << ans << "\n";
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 3672kb
input:
3 1 2 3
output:
2 6
result:
ok 2 number(s): "2 6"
Test #2:
score: -100
Wrong Answer
time: 1ms
memory: 3584kb
input:
1 1
output:
1 0
result:
wrong answer 2nd numbers differ - expected: '1', found: '0'