#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define endl "\n"
#define INF 1000000000
#define LINF 1000000000000000LL
#define pb push_back
#define all(x) x.begin(), x.end()
#define len(s) (int)s.size()
#define test_case { int t; cin>>t; while(t--)solve(); }
#define input(n, v) {for(int i = 0;i<n;i++) cin>>v[i];}
#define output(n, v) {for(int i = 0;i<n;i++) cout<<v[i]<<" "; cout<<endl;}
#define single_case solve();
#define line cout<<"------------"<<endl;
#define ios { ios_base::sync_with_stdio(false); cin.tie(NULL); }
const int N = 2e5 + 50;
vector<int> a;
int b[N];
int n;
int c[N];
int l, r;
int main()
{
ios
cin>>n;
for(int i = 1;i<=n;i++) cin>>b[i];
a.pb(b[1]);
c[b[1]]++;
int l = 1;
int r = 2*n-1;
for(int i = 2;i<=n;i++)
{
while(c[l])l++;
while(c[r])r--;
if(b[i]==b[i-1])
{
a.pb(l);
c[l]++;
a.pb(r);
c[r]++;
}
else
{
if(c[b[i]])
{
if(b[i]>b[i-1])
{
a.pb(r);
c[r]++;
r--;
while(!c[r])r--;
a.pb(r);
c[r]++;
r--;
}
else
{
a.pb(l);
c[l]++;
l++;
while(c[l])l++;
a.pb(l);
c[l]++;
l++;
}
}
else
{
a.pb(b[i]);
c[b[i]]++;
if(b[i]>b[i-1])
{
while(c[r])r--;
a.pb(r);
c[r]++;
}
else
{
while(c[l])l++;
a.pb(l);
l++;
}
}
}
}
for(int x : a) cout<<x<<" ";
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
492 KB |
Not a permutation |
2 |
Incorrect |
1 ms |
364 KB |
Not a permutation |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Runtime error |
1 ms |
492 KB |
Execution killed with signal 6 |
5 |
Incorrect |
1 ms |
364 KB |
Not a permutation |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Runtime error |
1 ms |
492 KB |
Execution killed with signal 6 |
8 |
Runtime error |
1 ms |
492 KB |
Execution killed with signal 6 |
9 |
Runtime error |
1 ms |
492 KB |
Execution killed with signal 6 |
10 |
Incorrect |
1 ms |
384 KB |
Not a permutation |
11 |
Runtime error |
1 ms |
492 KB |
Execution killed with signal 6 |
12 |
Runtime error |
1 ms |
620 KB |
Execution killed with signal 6 |
13 |
Runtime error |
2 ms |
620 KB |
Execution killed with signal 11 |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
2 ms |
620 KB |
Execution killed with signal 11 |
2 |
Runtime error |
3 ms |
620 KB |
Execution killed with signal 11 |
3 |
Runtime error |
2 ms |
748 KB |
Execution killed with signal 11 |
4 |
Runtime error |
3 ms |
876 KB |
Execution killed with signal 11 |
5 |
Runtime error |
5 ms |
1132 KB |
Execution killed with signal 11 |
6 |
Runtime error |
8 ms |
2028 KB |
Execution killed with signal 11 |
7 |
Runtime error |
12 ms |
2284 KB |
Execution killed with signal 11 |