This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define st first
#define nd second
signed main(){
cin.tie(0)->sync_with_stdio(0);
int n;
cin >> n;
int a[n + 1];
for(int i = 1; i <= n ; i++)
cin >> a[i];
int ans[n + 1];
int ptr = n, tmp = n - 1;
ans[n] = a[n];
while(ptr >= 1){
while(a[tmp] != a[ptr] && tmp >= 1){
ans[tmp] = ans[ptr];
tmp--;
}
ans[tmp] = ans[ptr];
ptr = tmp - 1;
ans[ptr] = a[ptr];
tmp = ptr - 1;
}
for(int i = 1 ; i <= n ; i++)
cout << ans[i] << endl;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |