QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#145394 | #6410. Classical DP Problem | Insert_Username_Here | WA | 2ms | 3712kb | C++20 | 1.2kb | 2023-08-22 10:43:17 | 2023-08-22 10:43:18 |
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 109
signed main() {
ios::sync_with_stdio(0);
cin.tie(0);
ll n;
cin >> n;
ll arr[n + 2][2], dp[n + 1][n + 1];
ll smax = 0, c = 1;
arr[0][0] = arr[0][1] = 0;
arr[n + 1][0] = arr[n + 1][1] = 0;
for(ll i = n; i > 0; i--) {
cin >> arr[i][0];
for(; c <= arr[i][0]; c++) arr[c][1] = i;
smax = max(smax, min(i + 1, arr[i][0]));
}
for(; c <= n; c++) arr[c][1] = 0;
for(ll i = 0; i <= n; i++) {
for(ll j = 0; j <= n; j++) dp[i][j] = 0;
}
dp[0][0] = 1;
ll fact = 1, ans = 0;
for(ll i = 2; i <= smax; i++) fact = fact * i % mod;
for(ll bk = 0; bk < 2; bk++) {
for(ll i = 0; i < smax; i++) {
dp[i + 1][0] = 0;
for(ll j = 0; j <= i; j++) {
dp[i + 1][j] = (dp[i + 1][j] + dp[i][j] * (arr[i + 1][bk] + j - arr[smax + 1][bk])) % mod;
dp[i + 1][j + 1] = dp[i][j] * (arr[smax + 1][bk] - j) % mod;
}
}
ans = (ans + dp[smax][arr[smax + 1][bk]]) % mod;
}
cout << smax << " " << (ans - fact + mod) % mod << "\n";
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 2ms
memory: 3708kb
input:
3 1 2 3
output:
2 6
result:
ok 2 number(s): "2 6"
Test #2:
score: 0
Accepted
time: 1ms
memory: 3612kb
input:
1 1
output:
1 1
result:
ok 2 number(s): "1 1"
Test #3:
score: 0
Accepted
time: 2ms
memory: 3712kb
input:
2 1 1
output:
1 2
result:
ok 2 number(s): "1 2"
Test #4:
score: 0
Accepted
time: 0ms
memory: 3644kb
input:
2 2 2
output:
2 6
result:
ok 2 number(s): "2 6"
Test #5:
score: 0
Accepted
time: 2ms
memory: 3588kb
input:
3 1 1 1
output:
1 3
result:
ok 2 number(s): "1 3"
Test #6:
score: 0
Accepted
time: 2ms
memory: 3712kb
input:
3 2 2 2
output:
2 9
result:
ok 2 number(s): "2 9"
Test #7:
score: 0
Accepted
time: 0ms
memory: 3636kb
input:
3 3 3 3
output:
3 48
result:
ok 2 number(s): "3 48"
Test #8:
score: 0
Accepted
time: 2ms
memory: 3664kb
input:
5 1 1 3 3 4
output:
3 47
result:
ok 2 number(s): "3 47"
Test #9:
score: 0
Accepted
time: 2ms
memory: 3712kb
input:
10 2 4 5 5 5 5 6 8 8 10
output:
5 864
result:
ok 2 number(s): "5 864"
Test #10:
score: -100
Wrong Answer
time: 2ms
memory: 3668kb
input:
30 6 8 9 9 9 10 13 14 15 15 16 17 17 18 20 22 22 23 23 24 24 25 25 25 27 28 28 29 29 30
output:
18 383552179
result:
wrong answer 1st numbers differ - expected: '17', found: '18'