QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#232927#6410. Classical DP Problemadelina_15WA 1ms3384kbC++141.9kb2023-10-31 01:14:032023-10-31 01:14:03

Judging History

你现在查看的是最新测评结果

  • [2023-10-31 01:14:03]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3384kb
  • [2023-10-31 01:14:03]
  • 提交

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'