QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#755487 | #7875. Queue Sorting | tkt0506 | WA | 0ms | 3804kb | C++14 | 1.2kb | 2024-11-16 17:28:58 | 2024-11-16 17:28:59 |
Judging History
answer
#include <bits/stdc++.h>
#define int long long
#define all(a) a.begin(),a.end()
using namespace std;
int32_t main(){
ios::sync_with_stdio(false);
cin.tie(0);
int n;
cin >> n;
vector<int> a(n+1), pre(n+1);
for(int i = 1; i <= n; i++) cin >> a[i];
for(int i = 1; i <= n; i++) pre[i] = pre[i-1] + a[i];
int m = pre[n];
vector<vector<int> > dp(n+1, vector<int>(m+1));
dp[1][0] = 1;
for(int i = 2; i <= n; i++){
for(int j = 0; j < pre[i-1]; j++){
dp[i][j] += dp[i-1][j];
for(int k = j+1; k <= pre[i-1]; k++){
for(int p = 1; p <= a[i]; p++){
dp[i][k] += dp[i-1][j] * pow(p, (k - j)); // 1-i filled, k is the front of last size 2
cout << i << ' ' << k << ' ' << dp[i][k] << '\n';
}
}
}
}
int ans = 0;
for(int i = 0; i <= m; i++){
ans += dp[n][i];
}
cout << ans << '\n';
}
// 2 1 2 1
// dp[i][j], 1..i inside b, j ist last element such that k > j && a[j] > a[k]
// insert i+1 into b => sum[1...i] - j + 1 places
// 4 1 2 3
// 2 1
// 3 1 2
// 2 1 3
// dp[3][1] = dp[3-1][1]
// dp[3][1] = dp[2][0] * 1
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 3804kb
input:
4 1 1 1 1
output:
2 1 1 3 1 1 3 2 1 3 2 2 4 1 1 4 2 1 4 3 1 4 2 3 4 3 3 4 3 5 14
result:
wrong answer 1st numbers differ - expected: '14', found: '2'