QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#275420#7875. Queue SortingWszytAC ✓176ms9280kbC++202.5kb2023-12-04 18:11:002023-12-04 18:11:00

Judging History

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

  • [2023-12-04 18:11:00]
  • 评测
  • 测评结果:AC
  • 用时:176ms
  • 内存:9280kb
  • [2023-12-04 18:11:00]
  • 提交

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;
    for (int i = 2; i < v.size(); i++) {
        for (int j = v[i]; j <= 501; 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 <= 501; 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 <= 501; 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;
}

这程序好像有点Bug,我给组数据试试?

詳細信息

Test #1:

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

input:

4
1 1 1 1

output:

14

result:

ok 1 number(s): "14"

Test #2:

score: 0
Accepted
time: 174ms
memory: 8428kb

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:

507010274

result:

ok 1 number(s): "507010274"

Test #3:

score: 0
Accepted
time: 174ms
memory: 9280kb

input:

500
1 1 0 2 1 0 2 3 2 0 0 2 0 2 1 1 0 0 1 1 1 2 1 1 1 0 1 1 2 2 1 4 0 2 1 0 2 3 1 0 1 1 0 2 1 2 2 1 0 0 3 1 4 1 1 2 1 1 0 1 3 1 2 0 0 0 2 1 2 0 0 3 2 1 1 1 1 1 2 1 0 1 0 0 0 1 0 0 2 1 1 0 1 0 1 0 1 0 0 1 0 1 1 0 0 0 1 0 0 0 2 1 1 0 1 1 0 1 1 0 0 1 0 3 1 3 0 0 2 0 0 1 1 0 0 0 0 0 1 0 0 0 0 0 1 2 0 0 ...

output:

7590964

result:

ok 1 number(s): "7590964"

Test #4:

score: 0
Accepted
time: 176ms
memory: 8324kb

input:

200
3 1 0 3 2 1 0 3 1 1 2 3 3 1 6 2 1 3 2 1 1 2 1 2 1 5 2 2 3 4 0 4 2 1 2 2 0 2 3 1 2 3 6 3 2 3 2 2 4 2 7 2 1 5 1 9 0 4 4 8 3 3 3 1 3 0 2 2 8 1 3 5 4 3 0 6 1 6 1 3 4 2 2 1 1 4 4 4 1 0 4 3 4 3 3 0 3 2 0 0 3 4 0 3 1 3 2 4 3 2 0 3 2 2 3 2 2 2 1 2 2 1 0 2 0 3 1 3 5 1 3 3 6 5 3 2 2 2 3 6 2 0 5 2 2 2 2 1 ...

output:

507844569

result:

ok 1 number(s): "507844569"

Test #5:

score: 0
Accepted
time: 106ms
memory: 8524kb

input:

100
4 8 2 5 4 4 3 0 2 7 2 3 4 4 1 2 3 4 4 4 3 3 3 3 3 2 4 1 3 5 5 1 4 6 1 1 1 3 2 3 2 1 0 1 4 4 2 4 2 5 3 5 1 6 2 3 3 1 4 4 4 1 4 4 3 4 2 0 2 3 6 1 3 3 5 4 1 1 2 3 0 3 2 2 1 3 3 2 5 6 3 2 3 3 5 4 2 3 4 4

output:

989550242

result:

ok 1 number(s): "989550242"

Test #6:

score: 0
Accepted
time: 0ms
memory: 9108kb

input:

1
1

output:

1

result:

ok 1 number(s): "1"

Test #7:

score: 0
Accepted
time: 2ms
memory: 8748kb

input:

500
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ...

output:

1

result:

ok 1 number(s): "1"

Test #8:

score: 0
Accepted
time: 8ms
memory: 8340kb

input:

10
2 1 3 3 2 3 1 1 3 1

output:

165452340

result:

ok 1 number(s): "165452340"

Test #9:

score: 0
Accepted
time: 2ms
memory: 8816kb

input:

20
0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 0 0 0 0 0

output:

2

result:

ok 1 number(s): "2"

Test #10:

score: 0
Accepted
time: 0ms
memory: 8600kb

input:

20
0 0 1 0 0 0 0 1 0 0 0 0 0 0 2 0 1 0 0 0

output:

28

result:

ok 1 number(s): "28"

Test #11:

score: 0
Accepted
time: 2ms
memory: 8912kb

input:

10
1 1 1 1 1 1 1 1 1 1

output:

16796

result:

ok 1 number(s): "16796"

Test #12:

score: 0
Accepted
time: 106ms
memory: 8736kb

input:

300
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ...

output:

431279497

result:

ok 1 number(s): "431279497"

Test #13:

score: 0
Accepted
time: 96ms
memory: 8560kb

input:

2
232 268

output:

929717758

result:

ok 1 number(s): "929717758"

Test #14:

score: 0
Accepted
time: 2ms
memory: 7628kb

input:

1
500

output:

1

result:

ok 1 number(s): "1"

Test #15:

score: 0
Accepted
time: 119ms
memory: 8992kb

input:

3
155 180 165

output:

911108550

result:

ok 1 number(s): "911108550"

Extra Test:

score: 0
Extra Test Passed