#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(-2, -2));
book[one].push_back(make_pair(n+1, n+1));
}
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(cl-lb!=1 && rb-cr!=1){insidx = cr; two = nums+2; one = 31;}
else{book[one][two+1].second = -2; two++;}
}
}
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 << ' ';}
}
}
Compilation message
zalmoxis.cpp: In function 'int main()':
zalmoxis.cpp:37:24: warning: assuming signed overflow does not occur when assuming that (X + c) >= X is always true [-Wstrict-overflow]
for(ll two = 1; two <= nums; two++){
~~~~^~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
532 ms |
43216 KB |
Output is correct |
2 |
Correct |
533 ms |
43700 KB |
Output is correct |
3 |
Correct |
568 ms |
42928 KB |
Output is correct |
4 |
Correct |
562 ms |
43900 KB |
Output is correct |
5 |
Correct |
543 ms |
44068 KB |
Output is correct |
6 |
Correct |
543 ms |
45400 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
569 ms |
42560 KB |
Unexpected end of file - int32 expected |
2 |
Incorrect |
399 ms |
27356 KB |
Unexpected end of file - int32 expected |
3 |
Incorrect |
389 ms |
26720 KB |
Unexpected end of file - int32 expected |
4 |
Incorrect |
527 ms |
43600 KB |
Unexpected end of file - int32 expected |
5 |
Incorrect |
523 ms |
44112 KB |
Unexpected end of file - int32 expected |
6 |
Incorrect |
537 ms |
46176 KB |
Unexpected end of file - int32 expected |
7 |
Incorrect |
557 ms |
44252 KB |
Unexpected end of file - int32 expected |
8 |
Incorrect |
432 ms |
30680 KB |
Unexpected end of file - int32 expected |
9 |
Incorrect |
311 ms |
22660 KB |
Unexpected end of file - int32 expected |
10 |
Incorrect |
118 ms |
8632 KB |
Unexpected end of file - int32 expected |
11 |
Incorrect |
212 ms |
14840 KB |
Unexpected end of file - int32 expected |
12 |
Incorrect |
2 ms |
256 KB |
Unexpected end of file - int32 expected |
13 |
Incorrect |
2 ms |
256 KB |
Unexpected end of file - int32 expected |
14 |
Incorrect |
2 ms |
376 KB |
Unexpected end of file - int32 expected |