fork download
  1. /*
  2.   Author: Nguyen Nhut Truong
  3.   From Chuyen Tien Giang High School For The Gifed
  4. */
  5. #include <bits/stdc++.h>
  6. using namespace std;
  7.  
  8. //#define int long long
  9. #define start signed main
  10. #define fi first
  11. #define se second
  12. #define pb push_back
  13. #define eb emplace_back
  14. #define il pair<int,ll>
  15. #define ii pair<int,int>
  16. #define len(s) (int)s.size()
  17. #define all(s) (s).begin(),(s).end()
  18. #define OpenFile(Name) if (fopen(Name".inp","r")) freopen(Name".inp","r",stdin),freopen(Name".out","w",stdout);
  19.  
  20. #define MASK(x) ((1LL)<<(x))
  21. #define Bit(x,i) (((x)>>(i))&1)
  22. #define Countbit(x) __builtin_popcountll(x)
  23.  
  24. typedef long long ll;
  25. typedef long double ld;
  26.  
  27. int dx[]={1,-1,0,0,-1,1,1,-1};
  28. int dy[]={0,0,1,-1,-1,-1,1,1};
  29.  
  30. template <class C> bool Minimize(C &a, C b) { if (a>b) { a=b; return true; } return false;}
  31. template <class C> bool Maximize(C &a, C b) { if (a<b) { a=b; return true; } return false;}
  32.  
  33. inline ll add(ll a,ll b,ll c) { return (a+b)%c; };
  34. inline ll suf(ll a,ll b,ll c) { return (a-b+c)%c; };
  35. inline ll mul(ll a,ll b,ll c) { return ((a%c)*(b%c))%c; };
  36.  
  37. mt19937_64 rd(chrono::steady_clock::now().time_since_epoch().count());
  38.  
  39. ll rand(ll l,ll r){
  40. assert(l<=r);
  41. return l+rd()%(r-l+1);
  42. }
  43.  
  44. void MakeInp() {
  45. ofstream cout("Task.inp");
  46.  
  47. ll n=rand(1,1000),s=rand(1,1000);
  48. cout<<n<<' '<<s<<endl;
  49. for (int i=1;i<=n;++i) {
  50. ll f=rand(0,1e3);
  51. cout<<f<<' ';
  52. }
  53.  
  54.  
  55. cout.close();
  56. }
  57.  
  58. /// Constant Limit
  59.  
  60. const int N=1e6+5,M=1e3+5,INF=1e9,lim=1e6;
  61. const int block=448,base=31;
  62.  
  63. ll Mod=998244353,Mod_base=1777777777,LNF=1e18;
  64.  
  65. ///________________________________________________________________________________________________________
  66.  
  67. int n;
  68. ll a[N],s;
  69.  
  70. namespace task1 {
  71. void solve() {
  72. ll res=0;
  73. for (int mask=1;mask<MASK(n);++mask) {
  74. ll cur=0;
  75. for (int i=1;i<=n;++i)
  76. if (Bit(mask,i-1)) cur+=a[i];
  77.  
  78. if (cur==s) res++;
  79. }
  80.  
  81. cout<<res%Mod;
  82. }
  83. }
  84.  
  85. namespace task2 {
  86. void solve() {
  87. int res=0;
  88. vector<vector<ll>> dp(n+3,vector<ll>(s+3,0));
  89.  
  90. dp[0][0]=1;
  91. for (int i=1;i<=n;++i)
  92. for (int j=0;j<=s;++j) {
  93. dp[i][j]=dp[i-1][j];
  94. if (j-a[i]>=0) dp[i][j]=add(dp[i][j],dp[i-1][j-a[i]],Mod);
  95. }
  96.  
  97. cout<<dp[n][s];
  98. }
  99. }
  100.  
  101. start() {
  102. ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
  103. OpenFile("TASK");
  104.  
  105. //MakeInp();
  106. cin>>n>>s;
  107. for (int i=1;i<=n;++i) cin>>a[i];
  108.  
  109. //task1::solve();
  110. //task2::solve();
  111. if (n<=20) task1::solve(); else task2::solve();
  112.  
  113.  
  114.  
  115.  
  116.  
  117.  
  118. //cerr<<"\nBien dich thanh cong\nTime: "<<(1.0*clock()/CLOCKS_PER_SEC)<<" s\n";
  119. return 0;
  120. }
  121.  
Success #stdin #stdout 0.01s 5268KB
stdin
Standard input is empty
stdout
Standard output is empty