Skip to content

Instantly share code, notes, and snippets.

@ramntry
Created July 5, 2014 13:47
Show Gist options
  • Save ramntry/929ece4c32d937360c3c to your computer and use it in GitHub Desktop.
Save ramntry/929ece4c32d937360c3c to your computer and use it in GitHub Desktop.
439
#include <cassert>
#include <cstdlib>
#include <cstring>
#include <cstdio>
#include <cctype>
#include <functional>
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <numeric>
#include <limits>
#include <vector>
#include <string>
#include <deque>
#include <set>
#include <map>
using namespace std;
#ifdef ONLINE_JUDGE
# define debug(...) (void)0
# define dump_vector(VECTOR) (void)0
# define LL_FORMAT "%I64d"
# define ULL_FORMAT "%I64u"
#else
# define debug(...) fprintf(stderr, __VA_ARGS__)
# define dump_vector(VECTOR) dump_named_vector(VECTOR, #VECTOR)
# define LL_FORMAT "%lld"
# define ULL_FORMAT "%llu"
#endif
typedef long long ll;
typedef unsigned long long ull;
#define DEFINE_MIN_MAX_CONSTANTS(TYPE) \
static int const TYPE##_max = numeric_limits<TYPE>::max(); \
static int const TYPE##_min = numeric_limits<TYPE>::min()
DEFINE_MIN_MAX_CONSTANTS(int);
DEFINE_MIN_MAX_CONSTANTS(ll);
DEFINE_MIN_MAX_CONSTANTS(ull);
DEFINE_MIN_MAX_CONSTANTS(double);
template <typename> struct stdio_format_for_type {};
#define DEFINE_STDIO_FORMAT_FOR_TYPE(TYPE, FORMAT) \
template <> struct stdio_format_for_type<TYPE> { static char const *const value; }; \
char const *const stdio_format_for_type<TYPE>::value = FORMAT
DEFINE_STDIO_FORMAT_FOR_TYPE(int, "%d");
DEFINE_STDIO_FORMAT_FOR_TYPE(ll, LL_FORMAT);
DEFINE_STDIO_FORMAT_FOR_TYPE(ull, ULL_FORMAT);
DEFINE_STDIO_FORMAT_FOR_TYPE(double, "%lf");
DEFINE_STDIO_FORMAT_FOR_TYPE(char const *, "%s");
template <typename E>
int read_back_vector(vector<E> &out, int size = int_max, char const *element_format = stdio_format_for_type<E>::value) {
E elem = E();
int i = 0;
for (; i < size; ++i) {
if (scanf(element_format, &elem) != 1) {
break;
}
out.push_back(elem);
}
return i;
}
template <typename E>
void read_in_vector(vector<E> &out, int size, char const *element_format = stdio_format_for_type<E>::value) {
out.resize(size);
for (int i = 0; i < size; ++i) {
assert(scanf(element_format, &out[i]) == 1);
}
}
#define read(TYPE, NAME) \
TYPE NAME = TYPE(); \
assert(scanf(stdio_format_for_type<TYPE>::value, &NAME) == 1)
#define read2(TYPE, NAME, TYPE2, NAME2) \
read(TYPE, NAME); \
read(TYPE2, NAME2)
#define read3(TYPE, NAME, TYPE2, NAME2, TYPE3, NAME3) \
read(TYPE, NAME); \
read2(TYPE2, NAME2, TYPE3, NAME3)
#define read2t(TYPE, NAME, NAME2) read2(TYPE, NAME, TYPE, NAME2)
#define read3t(TYPE, NAME, NAME2, NAME3) read3(TYPE, NAME, TYPE, NAME2, TYPE, NAME3)
#define read_vector(TYPE, NAME, SIZE) \
vector<TYPE> NAME; \
read_in_vector(NAME, SIZE)
template <typename E>
void dump_named_vector(vector<E> const &v, char const *name) {
int const size = v.size();
debug("[%2d] %10s = { ", size, name);
if (size) {
debug(stdio_format_for_type<E>::value, v[0]);
}
for (int i = 1; i < size; ++i) {
debug(", ");
debug(stdio_format_for_type<E>::value, v[i]);
}
debug(" }\n");
}
bool print_preceding_space;
template <typename T>
void print(T item, FILE *out = stdout) {
if (print_preceding_space) {
fprintf(out, " ");
}
fprintf(out, stdio_format_for_type<T>::value, item);
print_preceding_space = true;
}
void println(FILE *out = stdout) {
fprintf(out, "\n");
print_preceding_space = false;
}
template <typename T>
void println(T item, FILE *out = stdout) {
print(item, out);
println();
}
#define iter(COLLECTION_TEMPLATE, ITEM_TYPE, COLLECTION, ITERATOR_NAME) \
for (COLLECTION_TEMPLATE<ITEM_TYPE>::iterator ITERATOR_NAME = COLLECTION.begin(), \
ITERATOR_NAME##_end = COLLECTION.end(); ITERATOR_NAME != ITERATOR_NAME##_end; \
++ITERATOR_NAME)
#define all(COLLECTION) COLLECTION.begin(), COLLECTION.end()
int main() {
read3t(int, n, k, p);
read_vector(int, nums, n);
vector<int> odds;
vector<int> evens;
iter(vector, int, nums, it)
if (*it % 2 == 0)
evens.push_back(*it);
else
odds.push_back(*it);
int odd = odds.size();
int even = evens.size();
if (odd >= k - p && (odd - k + p) % 2 == 0 && p <= (odd - k + p) / 2 + even) {
println("YES");
int i = 0;
int j = 0;
for (; k > 0; --k) {
if (k != p) {
print(1);
println(odds[i]);
++i;
} else {
if (i < odd) {
print(2);
print(odds[i]);
println(odds[i + 1]);
i += 2;
} else {
print(1);
println(evens[j]);
++j;
}
}
}
print(odd - i + even - j);
for (; i < odd; ++i) {
print(odds[i]);
}
for (; j < even; ++j) {
print(evens[j]);
}
println();
} else {
println("NO");
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment