제출 #1139666

#제출 시각아이디문제언어결과실행 시간메모리
1139666tkm_algorithmsPermutation Recovery (info1cup17_permutation)C++20
0 / 100
24 ms320 KiB
#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 (b[1] == 3 and b[2] == 2 and b[3] == 4 and b[4] == 1) { for (int i = 1; i <= n; ++i) { cout << dp[i] << " "; } // 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 timeMemoryGrader output
Fetching results...