제출 #531970

#제출 시각아이디문제언어결과실행 시간메모리
531970Killer2501Magneti (COCI21_magneti)C++14
60 / 110
106 ms4780 KiB
#include <bits/stdc++.h> #define ll long long #define ld long double #define ull unsigned long long #define pb push_back #define pll pair<ll, ll> #define pii pair<ll, int> #define fi first #define se second using namespace std; const int N = 1e4+2; const int M = 52; const int mod = 1e9+7; const ll base = 75; const ll inf = 1e16; int n, lab[N], t, c[N+M], h[N], P[N][20], m, a[N], b[N+M], ans, d[N], k, lst[M][N], dp[M][N]; vector<int> adj[N]; vector<int> vi; string s; bool vis[N]; ll pw(ll k, ll n) { ll total = 1; for(; n; n >>= 1) { if(n&1)total = total * k % mod; k = k * k % mod; } return total; } void add(int& x, int y) { x += y; if(x >= mod)x -= mod; } int findp(int u) { return lab[u] < 0 ? u : lab[u] = findp(lab[u]); } void hop(int u, int v) { u = findp(u); v = findp(v); if(u == v)return; if(lab[u] > lab[v])swap(u, v); lab[u] += lab[v]; lab[v] = u; } int C(int u, int v) { if(u > v)return 0; return 1ll * b[v] * c[u] % mod * c[v-u] % mod; } void sol() { cin >> n >> m; for(int i = 1; i <= n; i ++)cin >> a[i]; b[0] = c[0] = 1; for(int i = 1; i <= m+n; i ++)b[i] = 1ll * b[i-1] * i % mod; c[m+n] = pw(b[m+n], mod-2); for(int i = m+n-1; i > 0; i --)c[i] = 1ll * c[i+1] * (i+1) % mod; sort(a+1, a+1+n); lst[1][1] = 1; for(int i = 2; i <= n; i ++) { memset(dp, 0, sizeof(dp)); for(int j = 1; j < i; j ++) { for(int l = i-1; l <= m; l ++) { add(dp[j+1][l+1], lst[j][l]); add(dp[j][l+a[i]], 2ll * j * lst[j][l] % mod); if(j > 1 && l+a[i]*2-1 <= m)add(dp[j-1][l+a[i]*2-1], 1ll * j * (j-1) * lst[j][l] % mod); } } swap(dp, lst); } for(int i = 1; i <= m; i ++)add(ans, 1ll * lst[1][i] * C(n, m-i+n) % mod); cout << ans; } int main() { cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0); #define task "test" if(fopen(task".inp", "r")) { freopen(task".inp", "r", stdin); freopen(task".out", "w", stdout); } int test = 1; //cin >> test; while(test -- > 0)sol(); return 0; } /* 1234 21 */

컴파일 시 표준 에러 (stderr) 메시지

Main.cpp: In function 'int main()':
Main.cpp:89:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   89 |         freopen(task".inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
Main.cpp:90:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   90 |         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...