//
// main.cpp
// u.cpp
//
// Created by Juri Aljohani on 30/11/2022.
//
#ifndef _GLIBCXX_NO_ASSERT
#include <cassert>
#endif
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#if __cplusplus >= 201103L
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
#endif
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#include <fstream>
#define int long long
#define endl '\n'
using namespace std;
int a[1000001];
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int n,k, p = 0, cur = 0, mn = INT_MAX, j = 0; cin >> n >> k;
deque<int>ans;
for(int i = 1; i <= n; i++){
cin >> a[i];
if(a[i] == a[i - 1]) p = i;
if(a[i] < mn){
mn = a[i];
j = i;
}
}
int l = p - 2, r = p + 1;
if(p == 0){
cur = mn;
ans.push_back(mn);
ans.push_back(mn);
l = j - 1; r = j + 1;
}else{
cur = a[p];
ans.push_back(a[p]);
ans.push_back(a[p]);
}
while(l >= 0 or r <= n){
int x = cur + 1, y = cur + 2, fa = 0, fb = 0, ff = 0;
if(l >= 0 && a[l] == x){
ans.push_front(x);
l--;
fa = 1;
ff = 1;
}else if(l >= 0 && a[l] == y){
ans.push_front(y);
l--;
fb = 1;
ff = 1;
}
if(r <= n && a[r] == x){
ans.push_back(x);
r++;
fa = 1;
}else if(r <= n && a[r] == y){
ans.push_back(y);
r++;
fb = 1;
}
if(fb + fa == 0) break;
if(!fa){
if((int)ans.size() + 1 > n + k) break;
if(!ff) ans.push_front(x);
else ans.push_back(x);
}
if(!fb){
if((int)ans.size() + 1 > n + k) break;
if(!ff) ans.push_front(y);
else ans.push_back(y);
}
cur += 2;
}
while(ans.size()){
cout << ans.front() << ' ' ;
ans.pop_front();
}
return 0;
}
/*
*/
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
51 ms |
9532 KB |
Unexpected end of file - int32 expected |
2 |
Incorrect |
63 ms |
9460 KB |
Unexpected end of file - int32 expected |
3 |
Incorrect |
52 ms |
9492 KB |
Unexpected end of file - int32 expected |
4 |
Incorrect |
65 ms |
9472 KB |
Unexpected end of file - int32 expected |
5 |
Incorrect |
47 ms |
9560 KB |
Unexpected end of file - int32 expected |
6 |
Incorrect |
46 ms |
9480 KB |
Unexpected end of file - int32 expected |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
53 ms |
9480 KB |
Unexpected end of file - int32 expected |
2 |
Incorrect |
48 ms |
9452 KB |
Unexpected end of file - int32 expected |
3 |
Incorrect |
49 ms |
9488 KB |
Unexpected end of file - int32 expected |
4 |
Incorrect |
51 ms |
9560 KB |
Unexpected end of file - int32 expected |
5 |
Incorrect |
69 ms |
9488 KB |
Unexpected end of file - int32 expected |
6 |
Incorrect |
51 ms |
9456 KB |
Unexpected end of file - int32 expected |
7 |
Incorrect |
47 ms |
9536 KB |
Unexpected end of file - int32 expected |
8 |
Incorrect |
48 ms |
9548 KB |
Unexpected end of file - int32 expected |
9 |
Incorrect |
43 ms |
7544 KB |
Unexpected end of file - int32 expected |
10 |
Incorrect |
17 ms |
2620 KB |
Unexpected end of file - int32 expected |
11 |
Incorrect |
25 ms |
4556 KB |
Unexpected end of file - int32 expected |
12 |
Incorrect |
0 ms |
212 KB |
Unexpected end of file - int32 expected |
13 |
Incorrect |
0 ms |
212 KB |
Unexpected end of file - int32 expected |
14 |
Incorrect |
1 ms |
212 KB |
Unexpected end of file - int32 expected |