#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define sz size()
#define ff first
#define ss second
#define pb push_back
#define pii pair <int, int>
#define dur exit(0)
#define dur1 return(0)
const int N = 2e5 + 5;
int dp[N], a[N], b[N];
int main () {
// freopen ("input.txt", "r", stdin);
ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
int n;
cin >> n;
for (int i = 1; i <= n; ++i) {
cin >> a[i];
}
// for (int i = 1; i <= n; ++i) {
// cout << i << " " << a[i] << "\n";
// }
// return 0;
for (int j = 1; j <= n; ++j) {
b[j] = j;
}
do {
dp[0] = 1;
for (int i = 1; i <= n; ++i) {
dp[i] = 0;
for (int j = i - 1; j >= 0; j--) {
if (b[i] > b[j]) {
dp[i] += dp[j];
}
}
}
// cout << a[1];
// return 0;
int jj = 0;
for (int i = 1; i <= n; ++i) {
if (i > 1)
dp[i] += dp[i - 1];
if (dp[i] != a[i]) {
jj = 1;
// cout << i << " " << dp[i] << " " << a[i] << "\n";
// return 0;
}
}
if (!jj) {
for (int i = 1; i <= n; ++i) {
cout << b[i] << " ";
}
return 0;
}
}while (next_permutation(b + 1, b + n + 1));
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |