제출 #1166147

#제출 시각아이디문제언어결과실행 시간메모리
1166147nhphucSkyscraper (JOI16_skyscraper)C++20
15 / 100
1 ms840 KiB
#include <bits/stdc++.h> using namespace std; const int N = 107; const int L = 1007; const int mod = 1e9 + 7; inline void add (int &a, int b){ a += b; if (a >= mod){ a -= mod; } return; } int mul (int a, int b){ return 1ll * a * b % mod; } int n, l, a[N], dp[N][N][L][3], ans = 0; int32_t main (){ ios::sync_with_stdio(false); cin.tie(nullptr); if (fopen ("test.inp", "r")){ freopen ("test.inp", "r", stdin); freopen ("test.out", "w", stdout); } cin >> n >> l; for (int i = 1; i <= n; ++i){ cin >> a[i]; } sort(a + 1, a + n + 1); dp[0][0][0][0] = 1; a[n + 1] = 100000; for (int i = 1; i <= n; ++i){ for (int j = 1; j <= n; ++j){ for (int k = 0; k <= l; ++k){ for (int e = 0; e <= 2; ++e){ int cost = (2 * j - e) * (a[i + 1] - a[i]); if (cost > k || i + j - e - 1 > n){ continue; } // case 1: add new component not contains endpoint add(dp[i][j][k][e], dp[i - 1][j - 1][k - cost][e]); // case 2: merge into a component but not be an endpoint add(dp[i][j][k][e], mul(dp[i - 1][j][k - cost][e], 2 * j - e)); // case 3: add new component contains endpoint if (e >= 1){ add(dp[i][j][k][e], mul(dp[i - 1][j - 1][k - cost][e - 1], 3 - e)); } // case 4: merge into a component and be an endpoint if (e == 1){ add(dp[i][j][k][e], mul(2 * j, dp[i - 1][j][k - cost][e - 1])); } if (e == 2){ if (i == n){ add(dp[i][j][k][e], dp[i - 1][j][k - cost][e - 1]); } else if (j > 1){ add(dp[i][j][k][e], mul(dp[i - 1][j][k - cost][e - 1], j - 1)); } } // case 5: insert to join 2 component if (e == 2){ if (i == n){ add(dp[i][j][k][e], dp[i - 1][j + 1][k - cost][e]); } else { add(dp[i][j][k][e], mul(dp[i - 1][j + 1][k - cost][e], j * (j - 1))); } } else { if (e == 1){ add(dp[i][j][k][e], mul(dp[i - 1][j + 1][k - cost][e], j * j)); } else { add(dp[i][j][k][e], mul(dp[i - 1][j + 1][k - cost][e], j * (j + 1))); } } } } } } for (int i = 0; i <= l; ++i){ add(ans, dp[n][1][i][2]); } cout << ans << "\n"; }

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

skyscraper.cpp: In function 'int32_t main()':
skyscraper.cpp:25:17: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   25 |         freopen ("test.inp", "r", stdin);
      |         ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
skyscraper.cpp:26:17: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   26 |         freopen ("test.out", "w", stdout);
      |         ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...