QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#232927 | #6410. Classical DP Problem | adelina_15 | WA | 1ms | 3384kb | C++14 | 1.9kb | 2023-10-31 01:14:03 | 2023-10-31 01:14:03 |
Judging History
answer
#include <iostream>
#include <vector>
using namespace std;
int n;
vector<int> a;
#define Mod 998244353
int dp[5005][5005];
bool OK(int i, int j)
{
if(a[i] >= j)
return true;
return false;
}
int KMin()
{
int i = n, j = 1, rez = 0;
while(OK(i, j))
{
i--;
j++;
rez++;
}
return rez;
}
int Linii(int k)
{
int x = a[k+1];
dp[0][x] = 1;
for(int i = 0; i <= k; i++)
for(int j = x; j >= 0; j--)
{
if(j > 0)
{
dp[i+1][j-1] += dp[i][j]*j;
dp[i+1][j-1]%=Mod;
}
dp[i+1][j] += dp[i][j]*(a[i+1]-j);
dp[i+1][j] %= Mod;
}
return dp[k][0];
}
void SchimbaA(vector<int> h)
{
vector<int> b;
b.resize(n+1);
for(int i = 1; i <= n; i++)
{
for(int j = 1; j <= h[i]; j++)
b[j]++;
}
a = b;
}
void RotireMat()
{
vector<int> hCol;
hCol.resize(n+1);
for(int i = 1; i <= n; i++)
{
int r = 0;
for(int j = 1; j <= n; j++)
if(a[j] >= a[i])
r++;
hCol[i] = r;
}
SchimbaA(hCol);
}
int Col()
{
RotireMat();
int k = KMin();
int x = a[k+1];
dp[0][x] = 1;
for(int i = 0; i <= k; i++)
for(int j = x; j >= 0; j--)
{
if(j > 0)
{
dp[i+1][j-1] += dp[i][j]*j;
dp[i+1][j-1]%=Mod;
}
dp[i+1][j] += dp[i][j]*(a[i+1]-j);
dp[i+1][j] %= Mod;
}
return dp[k][0];
}
int main()
{
cin >> n;
a.resize(n+1);
for(int i = 1; i <= n; i++)
cin >> a[i];
int k = KMin();
cout << k << " ";
for(int i = 1; i <= n/2; i++)
swap(a[i], a[n-i-1]);
cout << Linii(k)+Col()%Mod;;
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 1ms
memory: 3384kb
input:
3 1 2 3
output:
2 12
result:
wrong answer 2nd numbers differ - expected: '6', found: '12'