Submission #1139629

#TimeUsernameProblemLanguageResultExecution timeMemory
1139629KasymKPermutation Recovery (info1cup17_permutation)C++20
0 / 100
1095 ms324 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)

Main.cpp: In function 'int main()':
Main.cpp:23:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   23 |         scanf("%d", &n);
      |         ~~~~~^~~~~~~~~~
Main.cpp:25:22: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   25 |                 scanf("%lld", q+i);
      |                 ~~~~~^~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...