AtCoder Regular Contest 070

Submission #1353009

Source codeソースコード

#include<bits/stdc++.h>
using namespace std;
int n, k, a[5005], pre[5005][5005], suf[5005][5005], ans;

int main()
{
	scanf("%d%d",&n,&k);
	for(int i=1;i<=n;i++) {
		scanf("%d",&a[i]);
	}
	pre[0][0] = 1; suf[n+1][0] = 1;
	for(int i=1;i<=n;i++) {
		for(int j=0;j<=k;j++) {
			pre[i][j] |= pre[i-1][j];
			if(j >= a[i]) pre[i][j] |= pre[i-1][j-a[i]];
		}
	}
	for(int i=n;i>=1;i--) {
		for(int j=0;j<=k;j++) {
			suf[i][j] |= suf[i+1][j];
			if(j >= a[i]) suf[i][j] |= suf[i+1][j-a[i]];
		}
	}
	for(int i=1;i<=n+1;i++) {
		for(int j=1;j<=k;j++) suf[i][j] += suf[i][j-1];
	}
	for(int i=1;i<=n;i++) {
		for(int j=0;j<k;j++) {
			int X = k-j-a[i]-1;
			if(pre[i-1][j] && suf[i+1][k-j-1] - (X < 0 ? 0 : suf[i+1][X])) {ans++; break;}
		}
	}
	printf("%d\n",n-ans);
}

Submission

Task問題 D - No Need
User nameユーザ名 khsoo01
Created time投稿日時
Language言語 C++14 (GCC 5.4.1)
Status状態 AC
Score得点 600
Source lengthソースコード長 792 Byte
File nameファイル名
Exec time実行時間 199 ms
Memory usageメモリ使用量 195840 KB

Compiler messageコンパイルメッセージ

./Main.cpp: In function ‘int main()’:
./Main.cpp:7: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:9:20: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
scanf("%d",&a[i]);
^

Test case

Set

Set name Score得点 / Max score Cases
Sample - 0_000.txt,0_001.txt,0_002.txt
Subtask 300 / 300 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 300 / 300 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

Test case

Case name Status状態 Exec time実行時間 Memory usageメモリ使用量
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 2432 KB
1_007.txt AC 2 ms 2432 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 5 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 2432 KB
2_028.txt AC 2 ms 2432 KB
2_029.txt AC 191 ms 195840 KB
2_030.txt AC 199 ms 195840 KB
2_031.txt AC 148 ms 195840 KB
2_032.txt AC 39 ms 193408 KB
2_033.txt AC 148 ms 195840 KB
2_034.txt AC 39 ms 193408 KB
2_035.txt AC 39 ms 193408 KB
2_036.txt AC 161 ms 195840 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 129 ms 195840 KB
2_041.txt AC 103 ms 195072 KB
2_042.txt AC 137 ms 195840 KB
2_043.txt AC 85 ms 125184 KB
2_044.txt AC 99 ms 169856 KB
2_045.txt AC 65 ms 161152 KB
2_046.txt AC 106 ms 194944 KB
2_047.txt AC 141 ms 195712 KB
2_048.txt AC 170 ms 195840 KB
2_049.txt AC 165 ms 195840 KB
2_050.txt AC 162 ms 195840 KB