Submission #1232369

#TimeUsernameProblemLanguageResultExecution timeMemory
1232369hainam2k9Magneti (COCI21_magneti)C++20
110 / 110
34 ms12616 KiB
#include <bits/stdc++.h> #define tt cin.tie(0), cout.tie(0), ios_base::sync_with_stdio(0) #define fo freopen((NAME+".INP").c_str(), "r", stdin), freopen((NAME+".OUT").c_str(), "w", stdout) #define ll long long #define ull unsigned long long #define i128 __int128 #define db long double #define sz(a) ((int)(a).size()) #define pb emplace_back #define pf emplace_front #define pob pop_back #define pof pop_front #define lb lower_bound #define ub upper_bound #define fi first #define se second #define ins emplace #define mp make_pair using namespace std; const int MOD = 1e9+7, MAXN = 1e4+55; const string NAME = ""; int n,l,a[55],dp[55][55][MAXN],rs=0; int fact[MAXN]={1,1},inv[MAXN]={1,1}; void add(int& a, int b){ a+=b; if(a>=MOD) a-=MOD; } int modpow(int a, int b){ if(b==0) return 1; ll half=modpow(a,b>>1); half=(half*half)%MOD; if(b&1) return (half*a)%MOD; return half; } ll C(int n, int k){ return 1ll*fact[n]*(1ll*inv[k]*inv[n-k]%MOD)%MOD; } int main() { tt; if(fopen((NAME + ".INP").c_str(), "r")) fo; for(int i = 2; i<=1e4+50; ++i) fact[i]=1ll*fact[i-1]*i%MOD, inv[i]=modpow(fact[i],MOD-2); cin >> n >> l; for(int i = 1; i<=n; ++i) cin >> a[i]; sort(a+1,a+n+1); dp[0][0][0]=1; for(int i = 0; i<n; ++i) for(int j = 0; j<=i; ++j) for(int k = 0; k<l; ++k){ if(dp[i][j][k]==0) continue; add(dp[i+1][j+1][k],1ll*(j+1)*dp[i][j][k]%MOD); if(j>=1&&k+a[i+1]<l) add(dp[i+1][j][k+a[i+1]],2ll*j*dp[i][j][k]%MOD); if(j>=2&&k+2*a[i+1]<l) add(dp[i+1][j-1][k+2*a[i+1]],1ll*(j-1)*dp[i][j][k]%MOD); } for(int i = 0; i<l; ++i) add(rs,dp[n][1][i]*C(l-i+n-1,n)%MOD); cout << rs; }

Compilation message (stderr)

Main.cpp: In function 'int main()':
Main.cpp:3:19: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
    3 | #define fo freopen((NAME+".INP").c_str(), "r", stdin), freopen((NAME+".OUT").c_str(), "w", stdout)
      |            ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Main.cpp:41:45: note: in expansion of macro 'fo'
   41 |     if(fopen((NAME + ".INP").c_str(), "r")) fo;
      |                                             ^~
Main.cpp:3:63: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
    3 | #define fo freopen((NAME+".INP").c_str(), "r", stdin), freopen((NAME+".OUT").c_str(), "w", stdout)
      |                                                        ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Main.cpp:41:45: note: in expansion of macro 'fo'
   41 |     if(fopen((NAME + ".INP").c_str(), "r")) fo;
      |                                             ^~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...