Submission #1866598
Source Code Expand
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef long double ld;
#define MAXI 200020
#define u(x, a, b) for(ll x = a; x < b; x++)
#define d(x, a, b) for(ll x = a; x > b; x--)
vector<ll> sub(vector<ll> in, ll le, ll ri){
vector<ll> ans;
if(le == ri){
vector<ll> temp(1, 0);
ans = temp;
return ans;
}
u(two, le, ri){
ans.push_back(in[two]);
}
return ans;
}
deque< pair<ll, ll> > greedy(vector<ll> in){
deque< pair<ll, ll> > ans;
ll s = in.size(), min1 = MAXI, tar1 = -1, min2 = MAXI, tar2 = -1;
if(s == 1){
ans.push_back(make_pair(MAXI, MAXI));
return ans;
}
for(ll one = 0; one < s; one+=2){
if(in[one] < min1){
tar1 = one;
min1 = in[one];
}
}
for(ll one = tar1+1; one < s; one+=2){
if(in[one] < min2){
tar2 = one;
min2 = in[one];
}
}
ans.push_back(make_pair(min1, min2));
vector<ll> v1 = sub(in, 0, tar1), v2 = sub(in, tar1+1, tar2), v3 = sub(in, tar2+1, s);
deque< pair<ll, ll> > a1 = greedy(v1), a2 = greedy(v2), a3 = greedy(v3);
ll y = MAXI;
if(!a1.empty()){
y = min(a1[0].first, y);
}
if(!a2.empty()){
y = min(a2[0].first, y);
}
if(!a3.empty()){
y = min(a3[0].first, y);
}
while(y < MAXI){
if(y == a1[0].first){
ans.push_back(a1[0]);
a1.pop_front();
}
else if(y == a2[0].first){
ans.push_back(a2[0]);
a2.pop_front();
}
else{
ans.push_back(a3[0]);
a3.pop_front();
}
y = MAXI;
if(!a1.empty()){
y = min(a1[0].first, y);
}
if(!a2.empty()){
y = min(a2[0].first, y);
}
if(!a3.empty()){
y = min(a3[0].first, y);
}
}
return ans;
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
ll n, temp;
cin >> n;
vector<ll> arr;
u(three, 0, n){
cin >> temp;
arr.push_back(temp);
}
deque< pair<ll, ll> > fin = greedy(arr);
u(three, 0, n/2){
cout << fin[three].first << ' ' << fin[three].second << ' ';
}
}
Submission Info
Submission Time |
|
Task |
E - Young Maids |
User |
vjudge2 |
Language |
C++14 (GCC 5.4.1) |
Score |
0 |
Code Size |
2380 Byte |
Status |
RE |
Exec Time |
2268 ms |
Memory |
2083980 KB |
Judge Result
Set Name |
Sample |
All |
Score / Max Score |
0 / 0 |
0 / 800 |
Status |
|
|
Set Name |
Test Cases |
Sample |
0_00.txt, 0_01.txt, 0_02.txt |
All |
0_00.txt, 0_01.txt, 0_02.txt, 1_00.txt, 1_01.txt, 1_02.txt, 1_03.txt, 1_04.txt, 1_05.txt, 1_06.txt, 1_07.txt, 1_08.txt, 1_09.txt, 1_10.txt, 1_11.txt, 1_12.txt, 1_13.txt, 1_14.txt, 1_15.txt, 1_16.txt, 1_17.txt, 1_18.txt, 1_19.txt |
Case Name |
Status |
Exec Time |
Memory |
0_00.txt |
AC |
1 ms |
256 KB |
0_01.txt |
AC |
1 ms |
256 KB |
0_02.txt |
AC |
1 ms |
256 KB |
1_00.txt |
AC |
1 ms |
256 KB |
1_01.txt |
AC |
1 ms |
256 KB |
1_02.txt |
TLE |
2258 ms |
-1858880 KB |
1_03.txt |
TLE |
2243 ms |
-2084344 KB |
1_04.txt |
TLE |
2268 ms |
-1701248 KB |
1_05.txt |
RE |
156 ms |
7508 KB |
1_06.txt |
RE |
148 ms |
8532 KB |
1_07.txt |
RE |
123 ms |
9044 KB |
1_08.txt |
RE |
125 ms |
12628 KB |
1_09.txt |
TLE |
2240 ms |
2083980 KB |
1_10.txt |
TLE |
2263 ms |
-1743304 KB |
1_11.txt |
TLE |
2256 ms |
-1845500 KB |
1_12.txt |
RE |
122 ms |
7180 KB |
1_13.txt |
RE |
128 ms |
8408 KB |
1_14.txt |
RE |
126 ms |
10216 KB |
1_15.txt |
RE |
121 ms |
9564 KB |
1_16.txt |
RE |
123 ms |
11616 KB |
1_17.txt |
RE |
122 ms |
7508 KB |
1_18.txt |
RE |
126 ms |
8168 KB |
1_19.txt |
RE |
132 ms |
10600 KB |