Submission #1117568

#TimeUsernameProblemLanguageResultExecution timeMemory
1117568ntdaccodeMagneti (COCI21_magneti)C++17
110 / 110
89 ms8700 KiB
#include<bits/stdc++.h> #define fori(i,a,b) for(int i=a;i<=b;i++) #define int long long #define pb push_back using namespace std; typedef pair<int,int> ii; typedef tuple<int,int,int> tp; const int M = 1e4 + 10; const int N = 55; const int mod = 1e9 + 7; int n,l,r[N]; int f[2][N][M]; int power(int a,int n) { if(n == 0) return 1; int t = power(a,n/2); t = (t * t) % mod; if(n % 2) t = (t * a) % mod; return t; } int fact[M],ifact[M]; void tohop(int x = 1e4) { fact[0] = 1; for(int i = 1;i <= x; i++) fact[i] = (fact[i - 1] * i) % mod; ifact[x] = power(fact[x],mod - 2); for(int i = x - 1;i >= 0; i--) { ifact[i] = (ifact[i + 1] * (i + 1)) % mod; } } int C(int k,int n) { if(k > n) return 0; int res = 1; res = (res * fact[n]) % mod; res = (res * ifact[n - k]) % mod; res = (res * ifact[k]) % mod; return res; } void add(int &x,int y) { x += y; while(x >= mod) x -= mod; } int32_t main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); if(fopen("1.inp","r")) { freopen("1.inp","r",stdin); freopen("1.out","w",stdout); } #define task "" if(fopen(task".inp","r")) { freopen(task".inp","r",stdin); freopen(task".out","w",stdout); } cin >> n >> l; for(int i = 1;i <= n; i++) cin >> r[i]; sort(r + 1, r + n + 1); f[0][0][0] = 1; for(int i = 1;i <= n; i++) { for(int j = 1;j <= min(i,(n+1)/2) ; j++) { for(int e = 0;e <= l; e++) { if(e >= r[i]) add(f[i&1][j][e],2 * j * f[i-1&1][j][e - r[i]]); if(e >= 2 * r[i] - 1) add(f[i&1][j][e], (j + 1) * j * f[i-1&1][j + 1][e - 2 * r[i] + 1]); add(f[i&1][j][e], f[i-1&1][j - 1][e - 1]); } } for(int j = 0;j <= i; j++) for(int e = 0;e <= l; e++) f[i-1&1][j][e] = 0; } tohop(); int kq = 0; for(int i = 0;i <= l ; i++) { kq = (kq + f[n&1][1][i] * C(n, l + n - i ) % mod ) % mod; //cout << f[n&1][1][i] << " " <<i << "\n"; } cout << kq; }

Compilation message (stderr)

Main.cpp: In function 'int32_t main()':
Main.cpp:81:55: warning: suggest parentheses around '-' in operand of '&' [-Wparentheses]
   81 |             if(e >= r[i]) add(f[i&1][j][e],2 * j * f[i-1&1][j][e - r[i]]);
      |                                                      ~^~
Main.cpp:83:70: warning: suggest parentheses around '-' in operand of '&' [-Wparentheses]
   83 |             if(e >= 2 * r[i] - 1) add(f[i&1][j][e], (j + 1) * j * f[i-1&1][j + 1][e - 2 * r[i] + 1]);
      |                                                                     ~^~
Main.cpp:85:34: warning: suggest parentheses around '-' in operand of '&' [-Wparentheses]
   85 |             add(f[i&1][j][e], f[i-1&1][j - 1][e - 1]);
      |                                 ~^~
Main.cpp:90:40: warning: suggest parentheses around '-' in operand of '&' [-Wparentheses]
   90 |          for(int e = 0;e <= l; e++) f[i-1&1][j][e] = 0;
      |                                       ~^~
Main.cpp:61:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   61 |     freopen("1.inp","r",stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~
Main.cpp:62:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   62 |     freopen("1.out","w",stdout);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~
Main.cpp:67:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   67 |     freopen(task".inp","r",stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
Main.cpp:68:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   68 |     freopen(task".out","w",stdout);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...