Submission #1172088


Source Code Expand

Copy
#include<bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=a;i<b;i++)





#define rrep(i,a,b) for(int i=a;i>=b;i--)
int N, K, A[5050];
//-----------------------------------------------------------------------------------
int L[5010][5010], R[5010][5010];
void pre() {
	L[0][0] = 1;
	rep(i, 0, N) rep(j, 0, K) if (L[i][j]) {
		L[i + 1][j] = 1;
		if (j + A[i + 1] < K) L[i + 1][j + A[i + 1]] = 1;
	}

	R[N + 1][0] = 1;
	rrep(i, N, 1) rep(j, 0, K) if (R[i + 1][j]) {
		R[i][j] = 1;
		if (j + A[i] < K) R[i][j + A[i]] = 1;
	}

	// For optimized solution
	rep(i, 0, N + 2) {
		rep(j, 1, K) R[i][j] += R[i][j - 1];
	}
}
//-----------------------------------------------------------------------------------
int main() {
	cin >> N >> K;
	rep(i, 1, N + 1) scanf("%d", &A[i]);

	pre();

	int ans = 0;
	rep(i, 1, N + 1) {
		if (K <= A[i]) continue;

		bool ok = true;
		
		/* // Naive
		rep(j, 0, K) rep(k, 0, K) if (L[i - 1][j] && R[i + 1][k]) {
			if (K <= j + k + A[i] && j + k < K) ok = false;
		} */

		// Optimized
		rep(j, 0, K) if (L[i - 1][j]) {
			int lo = max(K - j - A[i], 0);
			int hi = min(K - 1, K - j - 1);

			int sm = R[i + 1][hi];
			if (0 < lo) sm -= R[i + 1][lo - 1];
			if (sm != 0) ok = false;
		}
		
		if (ok) ans++;
	}

	cout << ans << endl;
}

Submission Info

Submission Time
Task D - No Need
User hamayanhamayan
Language C++14 (GCC 5.4.1)
Score 600
Code Size 1336 Byte
Status AC
Exec Time 215 ms
Memory 196224 KB

Compile Error

./Main.cpp: In function ‘int main()’:
./Main.cpp:34:37: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
  rep(i, 1, N + 1) scanf("%d", &A[i]);
                                     ^

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 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 4480 KB
1_007.txt AC 2 ms 4480 KB
1_008.txt AC 6 ms 17280 KB
1_009.txt AC 6 ms 17280 KB
1_010.txt AC 5 ms 17280 KB
1_011.txt AC 5 ms 17024 KB
1_012.txt AC 5 ms 17280 KB
1_013.txt AC 5 ms 17024 KB
1_014.txt AC 5 ms 17024 KB
1_015.txt AC 6 ms 17280 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 5 ms 17152 KB
1_020.txt AC 5 ms 17024 KB
1_021.txt AC 5 ms 17152 KB
1_022.txt AC 3 ms 8960 KB
1_023.txt AC 3 ms 8832 KB
1_024.txt AC 5 ms 17152 KB
1_025.txt AC 5 ms 17152 KB
2_026.txt AC 2 ms 2304 KB
2_027.txt AC 2 ms 4480 KB
2_028.txt AC 2 ms 4480 KB
2_029.txt AC 189 ms 196224 KB
2_030.txt AC 188 ms 196224 KB
2_031.txt AC 132 ms 195072 KB
2_032.txt AC 39 ms 193536 KB
2_033.txt AC 132 ms 195072 KB
2_034.txt AC 39 ms 193536 KB
2_035.txt AC 39 ms 193536 KB
2_036.txt AC 215 ms 196224 KB
2_037.txt AC 2 ms 4608 KB
2_038.txt AC 2 ms 4608 KB
2_039.txt AC 2 ms 4608 KB
2_040.txt AC 120 ms 196224 KB
2_041.txt AC 132 ms 195200 KB
2_042.txt AC 180 ms 196224 KB
2_043.txt AC 102 ms 125184 KB
2_044.txt AC 118 ms 169856 KB
2_045.txt AC 75 ms 161024 KB
2_046.txt AC 101 ms 195200 KB
2_047.txt AC 134 ms 196096 KB
2_048.txt AC 160 ms 196224 KB
2_049.txt AC 156 ms 196224 KB
2_050.txt AC 152 ms 196224 KB