QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#149709 | #6410. Classical DP Problem | Insert_Username_Here | WA | 1ms | 3560kb | C++20 | 1.3kb | 2023-08-25 11:38:05 | 2023-08-25 11:38:06 |
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][2];
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, c = 0;
arr[n][0] = arr[n][1] = 0;
for(ll i = n - 1; i >= 0; i--) {
cin >> arr[i][0];
for(; c < arr[i][0]; c++) arr[c][1] = i + 1;
smax = max(smax, min(i + 1, arr[i][0]));
}
for(; c <= n; c++) arr[c][1] = 0;
ll ans = 0, cur, cols;
for(int bk = 0; bk < 2; bk++) {
cols = arr[smax][bk];
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][bk] - i) % mod;
}
if(i & 1) cur = -cur;
ans = (ans + cur + mod) % mod;
}
}
cout << smax << " " << (ans - fact[smax]) % mod << "\n";
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 3500kb
input:
3 1 2 3
output:
2 6
result:
ok 2 number(s): "2 6"
Test #2:
score: 0
Accepted
time: 1ms
memory: 3392kb
input:
1 1
output:
1 1
result:
ok 2 number(s): "1 1"
Test #3:
score: 0
Accepted
time: 1ms
memory: 3392kb
input:
2 1 1
output:
1 2
result:
ok 2 number(s): "1 2"
Test #4:
score: 0
Accepted
time: 1ms
memory: 3404kb
input:
2 2 2
output:
2 6
result:
ok 2 number(s): "2 6"
Test #5:
score: 0
Accepted
time: 1ms
memory: 3556kb
input:
3 1 1 1
output:
1 3
result:
ok 2 number(s): "1 3"
Test #6:
score: 0
Accepted
time: 1ms
memory: 3560kb
input:
3 2 2 2
output:
2 9
result:
ok 2 number(s): "2 9"
Test #7:
score: 0
Accepted
time: 1ms
memory: 3392kb
input:
3 3 3 3
output:
3 48
result:
ok 2 number(s): "3 48"
Test #8:
score: 0
Accepted
time: 1ms
memory: 3392kb
input:
5 1 1 3 3 4
output:
3 47
result:
ok 2 number(s): "3 47"
Test #9:
score: 0
Accepted
time: 1ms
memory: 3508kb
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: 1ms
memory: 3440kb
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:
17 -12054489
result:
wrong answer 2nd numbers differ - expected: '986189864', found: '-12054489'