QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#275409#7875. Queue SortingWszytWA 175ms8548kbC++202.5kb2023-12-04 18:04:022023-12-04 18:04:02

Judging History

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

  • [2023-12-04 18:04:02]
  • 评测
  • 测评结果:WA
  • 用时:175ms
  • 内存:8548kb
  • [2023-12-04 18:04:02]
  • 提交

answer

#pragma GCC optimize(2)
#pragma GCC optimize(3)
#pragma GCC optimize("Ofast")

#include<bits/stdc++.h>

#define eps 1e-7
#define endl "\n"
#define int long long
#define double long double
#define lowbit(x) (x&(-x))
#define stop system("pause")
#define INF 0x3f3f3f3f3f3f3f3f
#define NO cout << "NO" << endl
#define YES cout << "YES" << endl
#define w(s) cout << (#s) << " = " << (s) << endl
#define debug(x) for(int zyt=0;zyt<x;zyt++) cout<<'?';cout<<endl
#define IOS std::ios::sync_with_stdio(0), cin.tie(0), cout.tie(0)
using namespace std;
const int mod = 998244353;
const int N = 2e5;
int dp[505][505];
int cnt[505][505], pre[505][505];

void init() {
    for (int i = 0; i <= 500; i++) {
        for (int j = 0; j <= i; j++) {
            if (j == 0 || j == i)cnt[i][j] = 1;
            else cnt[i][j] = (cnt[i - 1][j - 1] + cnt[i - 1][j]) % mod;
        }
    }
    for (int i = 0; i <= 500; i++) {
        for (int j = 0; j <= 500; j++) {
            pre[i][j] = cnt[i][j];
            if (i - 1 >= 0)pre[i][j] = (pre[i - 1][j] + pre[i][j]) % mod;
        }
    }
}

void solve(int test) {
    int n;
    cin >> n;
    vector<int> v;
    v.push_back(0);
    for (int i = 1; i <= n; i++) {
        int x;
        cin >> x;
        if (x)v.push_back(x);
    }
    dp[1][v[1] + 1] = 1;
    map<int, int> sum;
    for (int i = 2; i < v.size(); i++) {
        for (int j = v[i]; j <= 500; j++)dp[i][j] = dp[i - 1][j - v[i]];//全部放前面的转移
//        for (int j = 2; j <= 500; j++) {
//            int l = 0, r = 0;
//            for (int k = 2; k <= 500; k++) {
//                if (j - 1 + v[i] - k >= 0) {
//                    int temp = max(0ll, pre[j - 1 + v[i] - k][r] - pre[j - 1 + v[i] - k][l - 1]);
//                    dp[i][k] = (dp[i][k] + dp[i - 1][j] * temp % mod) % mod;
//                }
//                if (r != v[i] - 1)r++;
//                else l++;
//            }
//        }
        for (int j = 2; j <= 500; j++) {
            for (int x = 0; x < v[i]; x++) {
                for (int k = 1; k < j; k++) {
                    dp[i][x + k + 1] =
                            (dp[i][x + k + 1] + dp[i - 1][j] * cnt[j - 1 - k + v[i] - x - 1][v[i] - x - 1] % mod) % mod;
                }
            }
        }
    }
    int ans = 0;
    for (int i = 2; i <= 500; i++) {
        ans = (ans + dp[v.size() - 1][i]) % mod;
    }
    cout << ans << endl;
}

signed main() {
    IOS;
    init();
    int T = 1;
//    cin >> T;
    for (int i = 1; i <= T; i++)solve(i);
    return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 3ms
memory: 8192kb

input:

4
1 1 1 1

output:

14

result:

ok 1 number(s): "14"

Test #2:

score: -100
Wrong Answer
time: 175ms
memory: 8548kb

input:

300
0 5 2 2 1 0 3 2 2 5 2 1 1 2 1 3 2 3 2 0 0 0 0 1 2 2 3 0 2 2 3 2 0 2 3 0 6 0 0 2 0 1 3 2 1 1 1 3 4 0 1 0 4 1 1 1 1 1 1 2 3 2 1 2 3 2 3 0 5 3 3 2 0 1 1 0 2 1 1 2 0 0 2 1 1 3 2 2 1 2 1 3 0 3 0 1 2 2 0 5 0 2 2 0 0 0 1 2 1 4 2 1 1 0 3 0 2 0 3 1 1 2 0 2 1 1 0 2 0 1 2 2 3 3 1 1 1 1 0 1 3 3 1 0 2 2 4 2 ...

output:

507010273

result:

wrong answer 1st numbers differ - expected: '507010274', found: '507010273'