QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#686214 | #6410. Classical DP Problem | badminton | WA | 1ms | 7800kb | C++14 | 1.8kb | 2024-10-29 08:54:17 | 2024-10-29 08:54:17 |
Judging History
answer
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair <ll,ll> pll;
typedef pair <int,int> pii;
typedef pair <int,pii> piii;
#define forr(_a,_b,_c) for(int _a = (_b); _a <= int (_c); ++_a)
#define ford(_a,_b,_c) for(int _a = (_b) + 1; _a --> int (_c);)
#define forf(_a,_b,_c) for(int _a = (_b); _a < int (_c); ++_a)
#define st first
#define nd second
#define pb push_back
#define mp make_pair
#define all(x) begin(x),end(x)
#define mask(i) (1LL << (i))
#define bit(x, i) (((x) >> (i)) & 1)
#define bp __builtin_popcountll
#define file "test"
template<class X, class Y>
bool minz(X &x, const Y &y) {
if (x > y) {
x = y;
return true;
} return false;
}
template<class X, class Y>
bool maxz(X &x, const Y &y) {
if (x < y) {
x = y;
return true;
} return false;
}
const int N = 5e5 + 5;
const ll oo = (ll) 1e16;
const ll mod = 998244353;
int n, m;
ll dp[N];
int calc(int *a){
int k = a[m];
forr (i, 0, k + 1)
dp[i] = 0;
dp[0] = 1;
forr (i, 0, m){
ford (j, min(i + 1, k), 1){
dp[j] = (((k - j + 1) * dp[j - 1] + (a[i] - k + j) * dp[j]) % mod);
}
dp[0] = (dp[0] * (a[i] - k)) % mod;
}
return dp[k];
}
int a[N], b[N];
void solve (){
cin >> n;
forr (i, 1, n){
cin >> a[i];
b[a[i]]++;
}
reverse(a + 1, a + 1 + n);
m = 1;
ford (i, n, 1){
b[i] += b[i + 1];
}
while (a[m] > m){
m++;
}
ll uwu = 1;
forr (i, 1, m)
uwu = uwu * i % mod;
cout << m << " " << (calc(a) + calc(b) - uwu + mod) % mod << "\n";
}
int main(){
ios_base::sync_with_stdio(0); cin.tie(0);
#ifdef kaguya
freopen(file".inp", "r", stdin); freopen(file".out", "w", stdout);
#endif
int q = 1;
// cin >> q;
while (q--)
solve();
return 0;
}
/*
*/
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 7800kb
input:
3 1 2 3
output:
2 6
result:
ok 2 number(s): "2 6"
Test #2:
score: -100
Wrong Answer
time: 1ms
memory: 7676kb
input:
1 1
output:
1 998244352
result:
wrong answer 2nd numbers differ - expected: '1', found: '998244352'