이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pl;
int main(){
ll n, k;
cin >> n >> k;
//all values between 1 and 30
//for k = 1
//smallest integer in input must have 2 consecutive of it, else insta solve
//group and ascend?
vector<pl> book[31];//book[i] stores pos of numbers i
for(ll one = 0; one < 31; one++){
book[one].push_back(make_pair(-1, -1));
book[one].push_back(make_pair(n, n));
}
ll tp, insidx = -1, insval = -1;
ll a[n];
for(ll one = 0; one < n; one++){
cin >> tp;
book[tp].push_back(make_pair(one, one));
a[one] = tp;
}
for(ll one = 0; one < 30; one++){
ll nums = book[one].size()-2;
sort(book[one].begin(), book[one].end());
if(nums%2){
insval = one;
for(ll two = 1; two <= nums; two++){
ll lb = book[one][two-1].second;
ll cl = book[one][two].first;
ll cr = book[one][two].second;
ll rb = book[one][two+1].first;
if(lb==-1 && rb==n){insidx = cr; two = nums+2; one = 31;}
else if(lb==-1){
if(rb-cr!=1){insidx = cr; two = nums+2; one = 31;}
}
else if(rb==n){
if(cl-lb!=1){insidx = cr; two = nums+2; one = 31;}
}
else if(cl-lb!=1 && rb-cr!=1){insidx = cr; two = nums+2; one = 31;}
}
}
else{
for(ll two = 1; two < nums; two+=2){
book[one+1].push_back(make_pair(book[one][two].first, book[one][two+1].second));
}
}
}
for(ll one = 0; one < n; one++){
cout << a[one] << ' ';
if(one == insidx){cout << insval << ' ';}
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |