Submission #3246423


Source Code Expand

#include<bits/stdc++.h>
using namespace std;

#define VA_NUM_ARGS(...) VA_NUM_ARGS_IMPL_((0,__VA_ARGS__, 6,5,4,3,2,1))
#define VA_NUM_ARGS_IMPL_(tuple) VA_NUM_ARGS_IMPL tuple
#define VA_NUM_ARGS_IMPL(_0,_1,_2,_3,_4,_5,_6,N,...) N
#define macro_dispatcher(macro, ...) macro_dispatcher_(macro, VA_NUM_ARGS(__VA_ARGS__))
#define macro_dispatcher_(macro, nargs) macro_dispatcher__(macro, nargs)
#define macro_dispatcher__(macro, nargs) macro_dispatcher___(macro, nargs)
#define macro_dispatcher___(macro, nargs) macro ## nargs
#define Debug1(a)           cout<<#a<<"="<<(a)<<"\n"
#define Debug2(a,b)         cout<<#a<<"="<<(a)<<", "<<#b<<"="<<(b)<<"\n"
#define Debug3(a,b,c)       cout<<#a<<"="<<(a)<<", "<<#b<<"="<<(b)<<", "<<#c<<"="<<(c)<<"\n"
#define Debug4(a,b,c,d)     cout<<#a<<"="<<(a)<<", "<<#b<<"="<<(b)<<", "<<#c<<"="<<(c)<<", "<<#d<<"="<<(d)<<"\n"
#define Debug5(a,b,c,d,e)   cout<<#a<<"="<<(a)<<", "<<#b<<"="<<(b)<<", "<<#c<<"="<<(c)<<", "<<#d<<"="<<(d)<<", "<<#e<<"="<<(e)<<"\n"
#define Debug6(a,b,c,d,e,f) cout<<#a<<"="<<(a)<<", "<<#b<<"="<<(b)<<", "<<#c<<"="<<(c)<<", "<<#d<<"="<<(d)<<", "<<#e<<"="<<(e)<<", "<<#f<<"="<<(f)<<"\n"
#define Debug(...) macro_dispatcher(Debug, __VA_ARGS__)(__VA_ARGS__)
#define DA(a,n) cout<<#a<<"=["; printarray(a,n); cout<<"]\n"
#define DAR(a,n,s) cout<<#a<<"["<<s<<"-"<<n-1<<"]=["; printarray(a,n,s); cout<<"]\n"

#define TT1 template<class T>
#define TT1T2 template<class T1, class T2>
#define TT1T2T3 template<class T1, class T2, class T3>
template<class T, size_t N> ostream& operator << (ostream& os, const array<T, N>& v);
TT1T2 ostream& operator << (ostream& os, const pair<T1, T2>& p){ return os <<"("<<p.first<<", "<< p.second<<")"; }
TT1 ostream& operator << (ostream& os, const vector<T>& v){       bool f=1;os<<"[";for(auto& i : v) { if (!f)os << ", ";os<<i;f=0;}return os << "]"; }
template<class T, size_t N> ostream& operator << (ostream& os, const array<T, N>& v) {     bool f=1;os<<"[";for(auto& i : v) { if (!f)os << ", ";os<<i;f=0;}return os << "]"; }
TT1T2 ostream& operator << (ostream& os, const set<T1, T2>&v){    bool f=1;os<<"[";for(auto& i : v) { if (!f)os << ", ";os<<i;f=0;}return os << "]"; }
TT1T2 ostream& operator << (ostream& os, const multiset<T1,T2>&v){bool f=1;os<<"[";for(auto& i : v) { if (!f)os << ", ";os<<i;f=0;}return os << "]"; }
TT1T2T3 ostream& operator << (ostream& os, const map<T1,T2,T3>& v){ bool f = 1; os << "["; for (auto& ii : v) { if (!f)os << ", "; os << "(" << ii.first << " -> " << ii.second << ") "; f = 0; }return os << "]"; }
TT1T2 ostream& operator << (ostream& os, const multimap<T1, T2>& v){ bool f = 1; os << "["; for (auto& ii : v) { if (!f)os << ", "; os << "(" << ii.first << " -> " << ii.second << ") "; f = 0; }return os << "]"; }
TT1T2 ostream& operator << (ostream& os, priority_queue<T1, T2> v) { bool f = 1; os << "["; while (!v.empty()) { auto x = v.top(); v.pop(); if (!f) os << ", "; f = 0; os << x; } return os << "]"; }
TT1T2 void printarray(const T1& a, T2 sz, T2 beg = 0){ for (T2 i = beg; i<sz; i++) cout << a[i] << " "; cout << endl; }

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> Pi;
typedef pair<ll, ll> Pll;

#define Fi first
#define Se second
#define pb(x) push_back(x)
#define sz(x) (int)x.size()
#define rep(i, n) for(int i=0;i<n;i++)
#define repp(i, n) for(int i=1;i<=n;i++)
#define all(x) x.begin(), x.end()
#define geti1(X) cin >> X
#define geti2(X,Y) cin >> X >> Y
#define geti3(X,Y,Z) cin >> X >> Y >> Z
#define geti4(X,Y,Z,W) cin >> X >> Y >> Z >> W
#define GET_MACRO(_1,_2,_3,_4,NAME,...) NAME
#define geti(...) GET_MACRO(__VA_ARGS__, geti4, geti3, geti2, geti1) (__VA_ARGS__)

#define INF 987654321

#define endl '\n'
int dp1[5050][5050];
int dp2[5050][5050];
int s1[5050], s2[5050];
int p[5050];
int N,K;
int main() {
	scanf("%d%d",&N,&K);
	int ans = 0;
	vector<int> v;
	repp(i,N){
		int x; scanf("%d",&x);
		if( x >= K ){
			continue;
		}
		v.pb(x);
	}
	N = sz(v); repp(i,N) p[i] = v[i-1];

	dp1[0][0] = 1;
	for(int i=1;i<=N;i++){
		for(int j=0;j<=K;j++){
			dp1[i][j] |= dp1[i-1][j];
			if( j - p[i] >= 0 ) dp1[i][j] |= dp1[i-1][j-p[i]];
		}
	}
	dp2[N+1][0] = 1;
	for(int i=N;i>=1;i--){
		for(int j=0;j<=K;j++){
			dp2[i][j] |= dp2[i+1][j];
			if( j - p[i] >= 0 ) dp2[i][j] |= dp2[i+1][j-p[i]];
		}
	}

	for(int i=1;i<=N;i++){
		memset(s1,0,sizeof s1);
		memset(s2,0,sizeof s2);

		s2[0] = 1;
		for(int j=1;j<=K;j++) s2[j] = s2[j-1] + dp2[i+1][j];

		bool flag = true;
		for(int j=0;j<=K;j++){
			if( dp1[i-1][j] == 0 ) continue;
			int l = K-p[i]-j;
			int r = K-j-1;
			if( r < 0 ) continue;
			if( l > r ) continue;
			int sum = s2[r];
			if( l > 0 ) sum -= s2[l-1];
			if( sum ) flag = false; 
		}
		
		if( flag ) ans++;
	}


	printf("%d\n",ans);
}

Submission Info

Submission Time
Task D - No Need
User kjp4155
Language C++14 (GCC 5.4.1)
Score 600
Code Size 4839 Byte
Status AC
Exec Time 211 ms
Memory 198912 KB

Compile Error

./Main.cpp: In function ‘int main()’:
./Main.cpp:63:21: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d%d",&N,&K);
                     ^
./Main.cpp:67:24: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
   int x; scanf("%d",&x);
                        ^

Judge Result

Set Name Sample Subtask All
Score / Max Score 0 / 0 300 / 300 300 / 300
Status
AC × 3
AC × 26
AC × 51
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 1 ms 2432 KB
0_002.txt AC 1 ms 2304 KB
1_003.txt AC 2 ms 2304 KB
1_004.txt AC 2 ms 2304 KB
1_005.txt AC 1 ms 2304 KB
1_006.txt AC 2 ms 2432 KB
1_007.txt AC 1 ms 2432 KB
1_008.txt AC 6 ms 17280 KB
1_009.txt AC 6 ms 17280 KB
1_010.txt AC 1 ms 2304 KB
1_011.txt AC 1 ms 2304 KB
1_012.txt AC 2 ms 2304 KB
1_013.txt AC 1 ms 2304 KB
1_014.txt AC 1 ms 2304 KB
1_015.txt AC 6 ms 17280 KB
1_016.txt AC 1 ms 2432 KB
1_017.txt AC 1 ms 2432 KB
1_018.txt AC 1 ms 2432 KB
1_019.txt AC 1 ms 2432 KB
1_020.txt AC 4 ms 14976 KB
1_021.txt AC 5 ms 17152 KB
1_022.txt AC 3 ms 6912 KB
1_023.txt AC 2 ms 4736 KB
1_024.txt AC 3 ms 11008 KB
1_025.txt AC 4 ms 8960 KB
2_026.txt AC 2 ms 2304 KB
2_027.txt AC 2 ms 2432 KB
2_028.txt AC 2 ms 2432 KB
2_029.txt AC 206 ms 198912 KB
2_030.txt AC 206 ms 198912 KB
2_031.txt AC 2 ms 2304 KB
2_032.txt AC 2 ms 2304 KB
2_033.txt AC 2 ms 2304 KB
2_034.txt AC 2 ms 2304 KB
2_035.txt AC 2 ms 2304 KB
2_036.txt AC 211 ms 198912 KB
2_037.txt AC 2 ms 2560 KB
2_038.txt AC 2 ms 2560 KB
2_039.txt AC 2 ms 2560 KB
2_040.txt AC 2 ms 2560 KB
2_041.txt AC 132 ms 198400 KB
2_042.txt AC 178 ms 198912 KB
2_043.txt AC 75 ms 84096 KB
2_044.txt AC 89 ms 116608 KB
2_045.txt AC 57 ms 109952 KB
2_046.txt AC 64 ms 99968 KB
2_047.txt AC 86 ms 102528 KB
2_048.txt AC 102 ms 100608 KB
2_049.txt AC 81 ms 80128 KB
2_050.txt AC 68 ms 67840 KB