Submission #866843

#TimeUsernameProblemLanguageResultExecution timeMemory
866843prohackerSkyscraper (JOI16_skyscraper)C++14
15 / 100
1 ms860 KiB
#include <bits/stdc++.h> #define ll long long #define ld long double #define int long long using namespace std; const int N = 105; const int INF = INT_MAX; const int mod = 1e9+7; int n,lim,dp[N][N][1010][3],a[N]; int ans; void add(int &x, const int y) { x += y; if(x >= mod) { x -= mod; } } signed main() { if (fopen("task.inp", "r")) { freopen("task.inp", "r", stdin); freopen("task.out", "w", stdout); } ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> n >> lim; if(n == 1) { cout << 0; return 0; } for(int i = 1 ; i <= n ; i++) { cin >> a[i]; } sort(a+1,a+n+1); a[n+1] = 10010; dp[0][0][0][0] = 1; for(int i = 1 ; i <= n ; i++) { for(int j = 1 ; j <= i ; j++) { for(int k = 0 ; k <= lim ; k++) { for(int m = 0 ; m <= 2 ; m++) { int delta = (2*j-m)*(a[i+1]-a[i]); if(delta > k) { continue; } add(dp[i][j][k][m],dp[i-1][j-1][k-delta][m]); add(dp[i][j][k][m],1LL*(2*j-m)*dp[i-1][j][k-delta][m]%mod); if(m > 0) { if(j > 0) { add(dp[i][j][k][m],1LL*(3-m)*dp[i-1][j-1][k-delta][m-1]%mod); } if(m == 1) { add(dp[i][j][k][m],1LL*2*j*dp[i-1][j][k-delta][m-1]%mod); } else { if(i == n) { add(dp[i][j][k][m],dp[i-1][j][k-delta][m-1]); } else { if(j > 0) { add(dp[i][j][k][m],1LL*(j-1)*dp[i-1][j][k-delta][m-1]%mod); } } } } if(m == 2) { if(i == n) { add(dp[i][j][k][m],dp[i-1][j+1][k-delta][m]); } else { add(dp[i][j][k][m],1LL*j*(j-1)*dp[i-1][j+1][k-delta][m]%mod); } } else if(m == 1) { add(dp[i][j][k][m],1LL*j*j*dp[i-1][j+1][k-delta][m]%mod); } else { add(dp[i][j][k][m],1LL*j*(j+1)*dp[i-1][j+1][k-delta][m]%mod); } } } } } for(int i = 0 ; i <= lim ; i++) { add(ans,dp[n][1][i][2]); } cout << ans; return 0; }

Compilation message (stderr)

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