제출 #1278641

#제출 시각아이디문제언어결과실행 시간메모리
1278641vuquangsangMagneti (COCI21_magneti)C++20
0 / 110
157 ms105760 KiB
#include <bits/stdc++.h> using namespace std; #define ll long long #define FOR(i, a, b) for(int i = (a); i <= (b); i++) #define FORD(i, a, b) for(int i = (a); i >= (b); i--) #define el "\n" const int N = 2e4 + 2; const int sm = 1e9 + 7; int n, L, r[N]; long long dp[55][55][N]; void add(ll &x, ll y) { x += y; if(x >= sm) x -= sm; } ll fac[N], inv_fac[N]; ll Pow(int a, int n) { if(!n) return 1; ll res = Pow(a, n / 2); res = 1LL * res * res % sm; if(n & 1) res = 1LL * res * a % sm; return res; } void prepare() { int lim = n + L; fac[0] = inv_fac[0] = 1; FOR(i, 1, lim) fac[i] = 1LL * fac[i - 1] * i % sm; inv_fac[lim] = Pow(fac[lim], sm - 2); FORD(i, lim - 1, 1) inv_fac[i] = 1LL * inv_fac[i + 1] * (i + 1) % sm; } ll C(int k, int n) { if(k > n || k < 0) return 0; return 1LL * fac[n] * inv_fac[k] % sm * inv_fac[n - k] % sm; } void solve() { cin >> n >> L; for(int i = 1; i <= n; i++) cin >> r[i]; sort(r + 1, r + n + 1); dp[0][0][0] = 1; FOR(i, 1, n) FOR(j, 1, i) FOR(d, 1, L){ add(dp[i][j][d], dp[i - 1][j - 1][d - 1]); int R = r[i]; if(d >= R) add(dp[i][j][d], dp[i - 1][j][d - R] * 2 % sm * j % sm); if(d >= 2 * R - 1) add(dp[i][j][d], dp[i - 1][j + 1][d - 2 * R + 1] * j % sm * (j + 1) % sm); } prepare(); ll ans = 0; FOR(d, 1, L) { // x1 + x2 + .. + xn = L - d // x1 >= 0 // chia L - d o trong cho n + 1 nguoi //=> C(n, L - D + n) add(ans, 1LL * dp[n][1][d] * C(n, n + L - d)); } cout << ans; } main() { ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0); #define TASK "magneti" if(fopen(TASK".INP", "r")) { freopen(TASK".INP", "r", stdin); freopen(TASK".OUT", "w", stdout); } solve(); cerr << "\nTime" << 0.001 * clock() << "s "; return 0; }

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

Main.cpp:70:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   70 | main()
      | ^~~~
Main.cpp: In function 'int main()':
Main.cpp:76:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   76 |         freopen(TASK".INP", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
Main.cpp:77:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   77 |         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...