제출 #1155365

#제출 시각아이디문제언어결과실행 시간메모리
1155365yonatanlPermutation Recovery (info1cup17_permutation)C++20
0 / 100
0 ms324 KiB
#include <iostream> #include <vector> #include <algorithm> using namespace std; using ll = long long; using vll = vector<ll>; void solve() { ll n; cin >> n; vll q(n + 1); q[0] = 0; for (ll i = 1; i < n + 1; i++) { cin >> q[i]; } vll p(n + 1, -1); vll dp(n + 1, 0); ll addToDif = 0; for (ll num = 1; num <= n; num++) { ll dif = 1 + addToDif; //cout << "num = " << num << " dif = " << dif << endl; for (ll j = n; j > 0; j--) { //cout << "j = " << j << " q[j] = " << q[j] << " q[j - 1] = " << q[j - 1] << " dif = " << dif << endl; if (p[j] != -1) { dif -= dp[p[j]]; continue; } if (q[j] - q[j - 1] == dif) { p[j] = num; break; } } dp[num] = dif; addToDif += dp[num]; } for (ll i = 1; i <= n; i++) { cout << p[i] << " "; } cout << endl; } int main() { ios_base::sync_with_stdio(false); cin.tie(0); solve(); }
#Verdict Execution timeMemoryGrader output
Fetching results...