Submission #1516349
Source Code Expand
#include<bits/stdc++.h>
typedef long long ll;
typedef unsigned long long ull;
using namespace std;
#define pb push_back
int dy[]={0, 0, 1, -1, 1, 1, -1, -1};
int dx[]={1, -1, 0, 0, 1, -1, -1, 1};
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
#define mp make_pair
#define fi first
#define sc second
int n,x,w[40];
int saiki(int i,int s){
if(i == n){
return s == 0;
}
if(s == 0)
return 1;
if(s < 0)
return 0;
if((n - i) * w[i] < s)
return 0;
return saiki(i + 1,s) + saiki(i + 1,s - w[i]);
}
int dp[2][2000001];
int main(){
scanf("%d%d",&n,&x);
REP(i,n)
scanf("%d",w + i);
sort(w,w + n,greater<int>());
int s = 0;
REP(i,n)
s += w[i];
if(s < x){
printf("0\n");
return 0;
}else if(s == x){
printf("1\n");
return 0;
}
if(n < 27 || x > 2000000){
printf("%d\n",saiki(0,x));
return 0;
}
REP(i,x + 1)
dp[1][i] = 0;
dp[1][0] = 1;
RREP(i,n){
REP(j,x + 1){
dp[0][j] = dp[1][j] + ((j - w[i] >= 0) ? dp[1][j - w[i]] : 0);
}
REP(j,x + 1)
dp[1][j] = dp[0][j];
}
printf("%d\n",dp[1][x]);
return 0;
}
Submission Info
Submission Time |
|
Task |
A - 素数、コンテスト、素数 |
User |
kyawakyawa |
Language |
C++14 (GCC 5.4.1) |
Score |
0 |
Code Size |
1437 Byte |
Status |
RE |
Exec Time |
474 ms |
Memory |
256 KB |
Compile Error
./Main.cpp: In function ‘int main()’:
./Main.cpp:35:24: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
scanf("%d%d",&n,&x);
^
./Main.cpp:37:26: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
scanf("%d",w + i);
^
Judge Result
Set Name |
All |
Score / Max Score |
0 / 100 |
Status |
|
Set Name |
Test Cases |
All |
00_sample_01.txt, 00_sample_02.txt, 00_sample_03.txt, 00_sample_04.txt, 01_test_01.txt, 01_test_02.txt, 01_test_03.txt, 01_test_04.txt, 01_test_05.txt, 01_test_06.txt, 01_test_07.txt, 01_test_08.txt, 01_test_09.txt, 01_test_10.txt, 01_test_11.txt, 01_test_12.txt, 01_test_13.txt, 01_test_14.txt, 01_test_15.txt, 01_test_16.txt, 01_test_17.txt, 01_test_18.txt, 01_test_19.txt, 01_test_20.txt, 01_test_21.txt, 01_test_22.txt, 01_test_23.txt, 01_test_24.txt, 01_test_25.txt |
Case Name |
Status |
Exec Time |
Memory |
00_sample_01.txt |
WA |
1 ms |
256 KB |
00_sample_02.txt |
WA |
1 ms |
256 KB |
00_sample_03.txt |
RE |
463 ms |
256 KB |
00_sample_04.txt |
RE |
344 ms |
256 KB |
01_test_01.txt |
WA |
1 ms |
256 KB |
01_test_02.txt |
WA |
1 ms |
256 KB |
01_test_03.txt |
RE |
439 ms |
256 KB |
01_test_04.txt |
RE |
460 ms |
256 KB |
01_test_05.txt |
RE |
101 ms |
256 KB |
01_test_06.txt |
WA |
1 ms |
256 KB |
01_test_07.txt |
WA |
1 ms |
256 KB |
01_test_08.txt |
WA |
1 ms |
256 KB |
01_test_09.txt |
WA |
1 ms |
256 KB |
01_test_10.txt |
RE |
462 ms |
256 KB |
01_test_11.txt |
WA |
1 ms |
256 KB |
01_test_12.txt |
RE |
159 ms |
256 KB |
01_test_13.txt |
RE |
97 ms |
256 KB |
01_test_14.txt |
RE |
430 ms |
256 KB |
01_test_15.txt |
RE |
212 ms |
256 KB |
01_test_16.txt |
RE |
98 ms |
256 KB |
01_test_17.txt |
RE |
165 ms |
256 KB |
01_test_18.txt |
RE |
387 ms |
256 KB |
01_test_19.txt |
RE |
288 ms |
256 KB |
01_test_20.txt |
RE |
461 ms |
256 KB |
01_test_21.txt |
RE |
97 ms |
256 KB |
01_test_22.txt |
RE |
146 ms |
256 KB |
01_test_23.txt |
RE |
103 ms |
256 KB |
01_test_24.txt |
RE |
474 ms |
256 KB |
01_test_25.txt |
RE |
112 ms |
256 KB |