# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1139629 | KasymK | Permutation Recovery (info1cup17_permutation) | C++20 | 1095 ms | 324 KiB |
#include "bits/stdc++.h"
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
using namespace std;
#define ff first
#define ss second
#define all(v) v.begin(), v.end()
#define ll long long
#define pb push_back
#define pii pair<int, int>
#define pli pair<ll, int>
#define pll pair<ll, ll>
#define tr(i, c) for(auto i = c.begin(); i != c.end(); ++i)
#define wr puts("----------------")
template<class T>bool umin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
template<class T>bool umax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
const int N = 15;
ll q[N];
int main(){
int n;
scanf("%d", &n);
for(int i = 1; i <= n; ++i)
scanf("%lld", q+i);
vector<ll> p;
p.pb(0);
for(int i = 1; i <= n; ++i)
p.pb(i);
do{
vector<ll> dp(n+1, 0);
dp[0]=1;
for(int i = 1; i <= n; ++i)
for(int j = 0; j < i; ++j)
if(p[j]<p[i])
dp[i]+=dp[j];
dp[0]=0;
for(int i = 1; i <= n; ++i)
dp[i]+=dp[i-1];
bool ok=1;
for(int i = 1; i <= n and ok; ++i)
ok&=(dp[i]==q[i]);
if(ok){
for(int i = 1; i <= n; ++i)
printf("%lld ", p[i]);
puts("");
exit(0);
}
}while(next_permutation(p.begin()+1, p.end()));
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |