Submission #1167863


Source Code Expand

/*
* C++11 code template for contests.
* @author: Andrey Kalendarov
* @e-mail: andreykalendarov@gmail.com
*/

//#pragma GCC optimize ("O3")
//#define ANDREIKKAA_TOPCODER
//#define ANDREIKKAA_ALLOCATOR
#define ANDREIKKAA_CLASS Solution
#define ANDREIKKAA_METHOD solve
#define ANDREIKKAA_PARAMETERS void
#define ANDREIKKAA_CALL
#define ANDREIKKAA_RETURN_TYPE void

#define first x
#define second y
#include "bits/stdc++.h"
using namespace std;

typedef long long ll;
typedef long double ld;

#define endl '\n'
#define all(x) (x).begin(), (x).end()
#define sz(x) (int)(x).size()
const ld PI = acos(-1);

const int _ML = 500;
const char _inpf[] =
#if defined(ANDREIKKAA)
"input.txt"
#else
""
#endif
;
const char _outf[] =
#if defined(ANDREIKKAA)
""
#else
""
#endif
;

#if defined(ANDREIKKAA_ALLOCATOR)
char _mem[_ML * 1024LL * 1024LL];
size_t _ptr = 0;
inline void* operator new(size_t _x) { _ptr += _x; return _mem + _ptr - _x; }
inline void operator delete(void*) { }
#endif

template<typename T, typename U> inline ostream &operator << (ostream &_out, const pair<T, U> &_p) { _out << _p.first << ' ' << _p.second; return _out; }
template<typename T, typename U> inline istream &operator >> (istream &_in, pair<T, U> &_p) { _in >> _p.first >> _p.second; return _in; }
template<typename T> inline ostream &operator << (ostream &_out, const vector<T> &_v) { if (_v.empty()) return _out; _out << _v.front(); for (auto _it = ++_v.begin(); _it != _v.end(); ++_it) _out << ' ' << *_it; return _out; }
template<typename T> inline istream &operator >> (istream &_in, vector<T> &_v) { for (auto &_i : _v) _in >> _i; return _in; }
template<typename T> inline ostream &operator << (ostream &_out, const set<T> &_s) { if (_s.empty()) return _out; _out << *_s.begin(); for (auto _it = ++_s.begin(); _it != _s.end(); ++_it) _out << ' ' << *_it; return _out; }
template<typename T> inline ostream &operator << (ostream &_out, const multiset<T> &_s) { if (_s.empty()) return _out; _out << *_s.begin(); for (auto _it = ++_s.begin(); _it != _s.end(); ++_it) _out << ' ' << *_it; return _out; }
template<typename T> inline ostream &operator << (ostream &_out, const unordered_set<T> &_s) { if (_s.empty()) return _out; _out << *_s.begin(); for (auto _it = ++_s.begin(); _it != _s.end(); ++_it) _out << ' ' << *_it; return _out; }
template<typename T> inline ostream &operator << (ostream &_out, const unordered_multiset<T> &_s) { if (_s.empty()) return _out; _out << *_s.begin(); for (auto _it = ++_s.begin(); _it != _s.end(); ++_it) _out << ' ' << *_it; return _out; }
template<typename T, typename U> inline ostream &operator << (ostream &_out, const map<T, U> &_m) { if (_m.empty()) return _out; _out << '(' << _m.begin()->first << ": " << _m.begin()->second << ')'; for (auto _it = ++_m.begin(); _it != _m.end(); ++_it) _out << ", (" << _it->first << ": " << _it->second << ')'; return _out; }
template<typename T, typename U> inline ostream &operator << (ostream &_out, const unordered_map<T, U> &_m) { if (_m.empty()) return _out; _out << '(' << _m.begin()->first << ": " << _m.begin()->second << ')'; for (auto _it = ++_m.begin(); _it != _m.end(); ++_it) _out << ", (" << _it->first << ": " << _it->second << ')'; return _out; }

/* ________ CODE ________ */

const int M = 10001;

bitset<M> f(bitset<M> &x, bitset<M> &y)
{
	bitset<M> z;
	for (int i = 0; i < M; ++i)
	{
		if (x[i])
		{
			z |= (y << i);
		}
	}
	return z;
}

inline ANDREIKKAA_RETURN_TYPE mainFunction(ANDREIKKAA_PARAMETERS)
{
	int n, k;
	cin >> n >> k;
	vector<bitset<M>> suf(n + 1);

	vector<int> a(n);
	cin >> a;

	suf[n][0] = 1;
	for (int i = n - 1; i >= 0; --i)
	{
		suf[i] = suf[i + 1] | (suf[i + 1] << a[i]);
		if (a[i] <= M)
		{
			suf[i] |= (suf[i + 1] << a[i]);
		}
	}

	bitset<M> now;
	now[0] = 1;
	int ans = n;
	for (int i = 0; i < n; ++i)
	{
		auto x = f(now, suf[i + 1]);
		if (a[i] < k)
		{
			for (int j = k - a[i]; j < k; ++j)
			{
				if (x[j])
				{
					--ans;
					break;
				}
			}
		}
		else
		{
			--ans;
		}
		

		if (a[i] <= M)
		{
			now |= (now << a[i]);
		}
	}
	cout << ans << endl;
}

/* ________ CODE ________ */

#if defined(ANDREIKKAA) || !defined(ANDREIKKAA_TOPCODER)
int main()
{
#if defined(ANDREIKKAA)
	time_t _start = clock();
#endif
	if (_inpf[0] != '\0')
		assert(freopen(_inpf, "r", stdin) != nullptr);
	if (_outf[0] != '\0')
		assert(freopen(_outf, "w", stdout) != nullptr);
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << setprecision(20);
	//cout << fixed;	
	mainFunction(ANDREIKKAA_CALL);
#if defined(ANDREIKKAA)
	cerr << "Time: " << (clock() - _start) / (ld)CLOCKS_PER_SEC << endl;
	while (true);
#endif
}
#else
class ANDREIKKAA_CLASS { public: ANDREIKKAA_RETURN_TYPE ANDREIKKAA_METHOD(ANDREIKKAA_PARAMETERS) { return mainFunction(ANDREIKKAA_CALL); } };
#endif

Submission Info

Submission Time
Task D - No Need
User Andreikkaa
Language C++14 (GCC 5.4.1)
Score 300
Code Size 4926 Byte
Status TLE
Exec Time 2103 ms
Memory 6400 KB

Judge Result

Set Name Sample Subtask All
Score / Max Score 0 / 0 300 / 300 0 / 300
Status
AC × 3
AC × 26
AC × 36
TLE × 15
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 1 ms 256 KB
0_001.txt AC 1 ms 256 KB
0_002.txt AC 1 ms 256 KB
1_003.txt AC 1 ms 256 KB
1_004.txt AC 1 ms 256 KB
1_005.txt AC 1 ms 256 KB
1_006.txt AC 2 ms 256 KB
1_007.txt AC 2 ms 256 KB
1_008.txt AC 38 ms 768 KB
1_009.txt AC 38 ms 768 KB
1_010.txt AC 6 ms 768 KB
1_011.txt AC 6 ms 768 KB
1_012.txt AC 9 ms 768 KB
1_013.txt AC 9 ms 768 KB
1_014.txt AC 1285 ms 768 KB
1_015.txt AC 1275 ms 768 KB
1_016.txt AC 1 ms 256 KB
1_017.txt AC 1 ms 256 KB
1_018.txt AC 1 ms 256 KB
1_019.txt AC 126 ms 768 KB
1_020.txt AC 133 ms 768 KB
1_021.txt AC 1195 ms 768 KB
1_022.txt AC 238 ms 512 KB
1_023.txt AC 40 ms 384 KB
1_024.txt AC 641 ms 768 KB
1_025.txt AC 781 ms 768 KB
2_026.txt AC 1 ms 256 KB
2_027.txt AC 3 ms 256 KB
2_028.txt AC 3 ms 256 KB
2_029.txt TLE 2103 ms 6400 KB
2_030.txt TLE 2103 ms 6400 KB
2_031.txt AC 55 ms 6400 KB
2_032.txt AC 56 ms 6400 KB
2_033.txt AC 62 ms 6400 KB
2_034.txt AC 63 ms 6400 KB
2_035.txt TLE 2103 ms 6400 KB
2_036.txt TLE 2103 ms 6400 KB
2_037.txt AC 3 ms 256 KB
2_038.txt AC 3 ms 256 KB
2_039.txt AC 4 ms 256 KB
2_040.txt TLE 2103 ms 6400 KB
2_041.txt TLE 2103 ms 6400 KB
2_042.txt TLE 2103 ms 6400 KB
2_043.txt TLE 2103 ms 4096 KB
2_044.txt TLE 2103 ms 5504 KB
2_045.txt TLE 2103 ms 5248 KB
2_046.txt TLE 2103 ms 6400 KB
2_047.txt TLE 2103 ms 6400 KB
2_048.txt TLE 2103 ms 6400 KB
2_049.txt TLE 2103 ms 6400 KB
2_050.txt TLE 2103 ms 6400 KB