//
// 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[200001];
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(a[l] == x){
ans.push_front(x);
l--;
fa = 1;
ff = 1;
}else if(a[l] == y){
ans.push_front(y);
l--;
fb = 1;
ff = 1;
}
if(a[r] == x){
ans.push_back(x);
r++;
fa = 1;
}else if(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 |
Runtime error |
12 ms |
3540 KB |
Execution killed with signal 11 |
2 |
Runtime error |
14 ms |
3524 KB |
Execution killed with signal 11 |
3 |
Runtime error |
11 ms |
3528 KB |
Execution killed with signal 11 |
4 |
Runtime error |
12 ms |
3604 KB |
Execution killed with signal 11 |
5 |
Runtime error |
11 ms |
3540 KB |
Execution killed with signal 11 |
6 |
Runtime error |
11 ms |
3540 KB |
Execution killed with signal 11 |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
11 ms |
3592 KB |
Execution killed with signal 11 |
2 |
Runtime error |
12 ms |
3600 KB |
Execution killed with signal 11 |
3 |
Runtime error |
11 ms |
3540 KB |
Execution killed with signal 11 |
4 |
Runtime error |
11 ms |
3540 KB |
Execution killed with signal 11 |
5 |
Runtime error |
14 ms |
3540 KB |
Execution killed with signal 11 |
6 |
Runtime error |
11 ms |
3632 KB |
Execution killed with signal 11 |
7 |
Runtime error |
12 ms |
3540 KB |
Execution killed with signal 11 |
8 |
Runtime error |
13 ms |
3540 KB |
Execution killed with signal 11 |
9 |
Runtime error |
12 ms |
3540 KB |
Execution killed with signal 11 |
10 |
Runtime error |
11 ms |
3540 KB |
Execution killed with signal 11 |
11 |
Runtime error |
14 ms |
3544 KB |
Execution killed with signal 11 |
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 |
0 ms |
212 KB |
Unexpected end of file - int32 expected |