Submission #1167854
Source Code Expand
#ifndef __clang__
#pragma GCC optimize "-O3"
#pragma GCC target "tune=native"
#endif
#ifdef ONLINE_JUDGE
#define NDEBUG 1
#endif
#include <stdio.h>
#include <bits/stdc++.h>
#define DESTRUCT2(p, a, b) \
auto a = get<0>(p); \
auto b = get<1>(p);
#define DESTRUCT3(p, a, b, c) \
auto a = get<0>(p); \
auto b = get<1>(p); \
auto c = get<2>(p);
#define DESTRUCT4(p, a, b, c, d) \
auto a = get<0>(p); \
auto b = get<1>(p); \
auto c = get<2>(p); \
auto d = get<3>(p);
#define FOR(i, n) for(lli i = 0; i < (lli)(n); ++i)
#define FORU(i, j, k) for(lli i = (j); i <= (lli)(k); ++i)
#define FORD(i, j, k) for(lli i = (j); i >= (lli)(k); --i)
#define SQ(x) ((x)*(x))
#define all(x) begin(x), end(x)
#define rall(x) rbegin(x), rend(x)
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define eb emplace_back
using namespace std;
template<typename... As>
struct tpl : public std::tuple<As...> {
using std::tuple<As...>::tuple;
template<typename T = tuple<As...> >
typename tuple_element<0, T>::type const&
x() const { return get<0>(*this); }
template<typename T = tuple<As...> >
typename tuple_element<0, T>::type&
x() { return get<0>(*this); }
template<typename T = tuple<As...> >
typename tuple_element<1, T>::type const&
y() const { return get<1>(*this); }
template<typename T = tuple<As...> >
typename tuple_element<1, T>::type&
y() { return get<1>(*this); }
template<typename T = tuple<As...> >
typename tuple_element<2, T>::type const&
z() const { return get<2>(*this); }
template<typename T = tuple<As...> >
typename tuple_element<2, T>::type&
z() { return get<2>(*this); }
template<typename T = tuple<As...> >
typename tuple_element<3, T>::type const&
w() const { return get<3>(*this); }
template<typename T = tuple<As...> >
typename tuple_element<3, T>::type&
w() { return get<3>(*this); }
};
using lli = long long int;
using llu = long long unsigned;
using pii = tpl<lli, lli>;
using piii = tpl<lli, lli, lli>;
using piiii = tpl<lli, lli, lli, lli>;
using vi = vector<lli>;
using vii = vector<pii>;
using viii = vector<piii>;
using vvi = vector<vi>;
using vvii = vector<vii>;
using vviii = vector<viii>;
template<class T>
using min_queue = priority_queue<T, vector<T>, greater<T> >;
template<class T>
using max_queue = priority_queue<T>;
template<size_t... I>
struct my_index_sequence {
using type = my_index_sequence;
static constexpr array<size_t, sizeof...(I)> value = { {I...} };
};
namespace my_index_sequence_detail {
template<typename I, typename J> struct concat;
template<size_t... I, size_t... J>
struct concat<my_index_sequence<I...>, my_index_sequence<J...> > :
my_index_sequence<I..., (sizeof...(I)+J)...> { };
template<size_t N> struct make_index_sequence :
concat<typename make_index_sequence<N/2>::type, typename make_index_sequence<N-N/2>::type>::type { };
template <> struct make_index_sequence<0> : my_index_sequence<>{};
template <> struct make_index_sequence<1> : my_index_sequence<0>{};
}
template<class... A>
using my_index_sequence_for = typename my_index_sequence_detail::make_index_sequence<sizeof...(A)>::type;
template<class T, size_t... I>
void print_tuple(ostream& s, T const& a, my_index_sequence<I...>){
using swallow = int[];
(void)swallow{0, (void(s << (I == 0? "" : ", ") << get<I>(a)), 0)...};
}
template<class T>
ostream& print_collection(ostream& s, T const& a);
template<class... A>
ostream& operator<<(ostream& s, tpl<A...> const& a);
template<class... A>
ostream& operator<<(ostream& s, tuple<A...> const& a);
template<class A, class B>
ostream& operator<<(ostream& s, pair<A, B> const& a);
template<class T, size_t I>
ostream& operator<<(ostream& s, array<T, I> const& a) { return print_collection(s, a); }
template<class T>
ostream& operator<<(ostream& s, vector<T> const& a) { return print_collection(s, a); }
template<class T, class U>
ostream& operator<<(ostream& s, multimap<T, U> const& a) { return print_collection(s, a); }
template<class T>
ostream& operator<<(ostream& s, multiset<T> const& a) { return print_collection(s, a); }
template<class T, class U>
ostream& operator<<(ostream& s, map<T, U> const& a) { return print_collection(s, a); }
template<class T>
ostream& operator<<(ostream& s, set<T> const& a) { return print_collection(s, a); }
template<class T>
ostream& print_collection(ostream& s, T const& a){
s << '[';
for(auto it = begin(a); it != end(a); ++it){
s << *it;
if(it != prev(end(a))) s << " ";
}
return s << ']';
}
template<class... A>
ostream& operator<<(ostream& s, tpl<A...> const& a){
s << '(';
print_tuple(s, a, my_index_sequence_for<A...>{});
return s << ')';
}
template<class... A>
ostream& operator<<(ostream& s, tuple<A...> const& a){
s << '(';
print_tuple(s, a, my_index_sequence_for<A...>{});
return s << ')';
}
template<class A, class B>
ostream& operator<<(ostream& s, pair<A, B> const& a){
return s << "(" << get<0>(a) << ", " << get<1>(a) << ")";
}
namespace std {
namespace {
template <class T>
inline void hash_combine(size_t& seed, T const& v) {
seed ^= hash<T>()(v) + 0x9e3779b9 + (seed<<6) + (seed>>2);
}
template <class Tuple, size_t Index = tuple_size<Tuple>::value - 1>
struct HashValueImpl {
static void apply(size_t& seed, Tuple const& tuple) {
HashValueImpl<Tuple, Index-1>::apply(seed, tuple);
hash_combine(seed, get<Index>(tuple));
}
};
template <class Tuple>
struct HashValueImpl<Tuple, 0> {
static void apply(size_t& seed, Tuple const& tuple) {
hash_combine(seed, get<0>(tuple));
}
};
}
template <typename ... TT>
struct hash<tuple<TT...>> {
size_t operator()(tuple<TT...> const& tt) const {
size_t seed = 0;
HashValueImpl<tuple<TT...> >::apply(seed, tt);
return seed;
}
};
template <typename ... TT>
struct hash<tpl<TT...>> {
size_t operator()(tpl<TT...> const& tt) const {
size_t seed = 0;
HashValueImpl<tuple<TT...> >::apply(seed, tt);
return seed;
}
};
}
lli read_positive(){
char c; lli x=0;
do { c = getchar(); } while(c<'0' || c>'9');
while(c>='0'&&c<='9') {
x=10*x+(c-'0');
c = getchar();
}
return x;
}
//------------------------------------------------------------------------------
lli a[5000];
bitset<5001> l[5001],r[5001];
short dt[5001];
int main(){
ios::sync_with_stdio(0); cin.tie(0);
int n,k; cin>>n>>k;
FOR(i,n) cin >> a[i];
l[0][0]=1; FOR(i,n) l[i+1] = l[i] | (l[i]<<a[i]);
r[n][0]=1; FORD(i,n-1,0) r[i] = r[i+1] | (r[i+1]<<a[i]);
int ans=0;
FOR(i,n) {
if(a[i]>=k) ans++;
else {
FORU(j,k-a[i],k-1) if(l[i][j] || r[i+1][j]) {
ans++; goto l_end;
}
memset(dt,0,sizeof(dt));
FORU(j,1,k-a[i]-1) if(l[i][j]) {
int from = k-a[i]-j;
int to = k-j-1;
if(from<=to) {
dt[from]++;
dt[to+1]--;
}
}
int cur=0;
FORU(j,1,k-a[i]-1) {
cur += dt[j];
if(cur && r[i+1][j]) { ans++; goto l_end; }
}
}
l_end:;
}
// int ans=0;
// FOR(j,n) {
// bitset<5001> b; b.reset(); b[0]=1;
// FOR(i,n) if(i!=j) b = b | (b<<a[i]);
// FORU(kk,max<lli>(0,k-a[j]),k-1) if(b[kk]) { ans++; break; }
// }
cout << n-ans << endl;
return 0;
}
Submission Info
Submission Time |
|
Task |
D - No Need |
User |
Rafbill |
Language |
C++14 (GCC 5.4.1) |
Score |
600 |
Code Size |
7826 Byte |
Status |
AC |
Exec Time |
78 ms |
Memory |
6528 KB |
Judge Result
Set Name |
Sample |
Subtask |
All |
Score / Max Score |
0 / 0 |
300 / 300 |
300 / 300 |
Status |
|
|
|
Set Name |
Test Cases |
Sample |
0_000.txt, 0_001.txt, 0_002.txt |
Subtask |
0_000.txt, 0_001.txt, 0_002.txt, 1_003.txt, 1_004.txt, 1_005.txt, 1_006.txt, 1_007.txt, 1_008.txt, 1_009.txt, 1_010.txt, 1_011.txt, 1_012.txt, 1_013.txt, 1_014.txt, 1_015.txt, 1_016.txt, 1_017.txt, 1_018.txt, 1_019.txt, 1_020.txt, 1_021.txt, 1_022.txt, 1_023.txt, 1_024.txt, 1_025.txt |
All |
0_000.txt, 0_001.txt, 0_002.txt, 1_003.txt, 1_004.txt, 1_005.txt, 1_006.txt, 1_007.txt, 1_008.txt, 1_009.txt, 1_010.txt, 1_011.txt, 1_012.txt, 1_013.txt, 1_014.txt, 1_015.txt, 1_016.txt, 1_017.txt, 1_018.txt, 1_019.txt, 1_020.txt, 1_021.txt, 1_022.txt, 1_023.txt, 1_024.txt, 1_025.txt, 2_026.txt, 2_027.txt, 2_028.txt, 2_029.txt, 2_030.txt, 2_031.txt, 2_032.txt, 2_033.txt, 2_034.txt, 2_035.txt, 2_036.txt, 2_037.txt, 2_038.txt, 2_039.txt, 2_040.txt, 2_041.txt, 2_042.txt, 2_043.txt, 2_044.txt, 2_045.txt, 2_046.txt, 2_047.txt, 2_048.txt, 2_049.txt, 2_050.txt |
Case Name |
Status |
Exec Time |
Memory |
0_000.txt |
AC |
2 ms |
2304 KB |
0_001.txt |
AC |
2 ms |
2304 KB |
0_002.txt |
AC |
2 ms |
2304 KB |
1_003.txt |
AC |
2 ms |
2304 KB |
1_004.txt |
AC |
2 ms |
2304 KB |
1_005.txt |
AC |
2 ms |
2304 KB |
1_006.txt |
AC |
2 ms |
2304 KB |
1_007.txt |
AC |
2 ms |
2304 KB |
1_008.txt |
AC |
3 ms |
2560 KB |
1_009.txt |
AC |
3 ms |
2560 KB |
1_010.txt |
AC |
2 ms |
2560 KB |
1_011.txt |
AC |
2 ms |
2560 KB |
1_012.txt |
AC |
2 ms |
2560 KB |
1_013.txt |
AC |
2 ms |
2560 KB |
1_014.txt |
AC |
2 ms |
2560 KB |
1_015.txt |
AC |
2 ms |
2560 KB |
1_016.txt |
AC |
2 ms |
2304 KB |
1_017.txt |
AC |
2 ms |
2304 KB |
1_018.txt |
AC |
2 ms |
2304 KB |
1_019.txt |
AC |
2 ms |
2560 KB |
1_020.txt |
AC |
2 ms |
2560 KB |
1_021.txt |
AC |
2 ms |
2560 KB |
1_022.txt |
AC |
2 ms |
2432 KB |
1_023.txt |
AC |
2 ms |
2432 KB |
1_024.txt |
AC |
2 ms |
2560 KB |
1_025.txt |
AC |
2 ms |
2560 KB |
2_026.txt |
AC |
2 ms |
2304 KB |
2_027.txt |
AC |
2 ms |
2304 KB |
2_028.txt |
AC |
2 ms |
2304 KB |
2_029.txt |
AC |
61 ms |
6528 KB |
2_030.txt |
AC |
78 ms |
6528 KB |
2_031.txt |
AC |
6 ms |
6528 KB |
2_032.txt |
AC |
6 ms |
6528 KB |
2_033.txt |
AC |
6 ms |
6528 KB |
2_034.txt |
AC |
6 ms |
6528 KB |
2_035.txt |
AC |
6 ms |
6528 KB |
2_036.txt |
AC |
6 ms |
6528 KB |
2_037.txt |
AC |
2 ms |
2304 KB |
2_038.txt |
AC |
2 ms |
2304 KB |
2_039.txt |
AC |
2 ms |
2304 KB |
2_040.txt |
AC |
6 ms |
6528 KB |
2_041.txt |
AC |
6 ms |
6528 KB |
2_042.txt |
AC |
6 ms |
6528 KB |
2_043.txt |
AC |
5 ms |
6272 KB |
2_044.txt |
AC |
6 ms |
6400 KB |
2_045.txt |
AC |
6 ms |
6400 KB |
2_046.txt |
AC |
24 ms |
6528 KB |
2_047.txt |
AC |
33 ms |
6528 KB |
2_048.txt |
AC |
40 ms |
6528 KB |
2_049.txt |
AC |
33 ms |
6528 KB |
2_050.txt |
AC |
29 ms |
6528 KB |