Submission #40163

#TimeUsernameProblemLanguageResultExecution timeMemory
40163evpipisSkyscraper (JOI16_skyscraper)C++98
100 / 100
126 ms131868 KiB
#include <bits/stdc++.h> using namespace std; const int len = 105, mod = 1e9+7; int n, a[len], dp[len][len][1005][3]; int solve(int i, int j, int rem, int l){ if (j < 0 || rem < 0 || l > 2) return 0; //printf("cur_state = %d, %d, %d, %d\n", i, j, rem, l); if (i == n+1) return (j == 1 && l == 2); if (dp[i][j][rem][l] != -1) return dp[i][j][rem][l]; int ans = 0, c = a[i+1]-a[i]; // Case 1: combine 2 ccs if (j >= 2){ int temp = solve(i+1, j-1, rem-c*(2*(j-1)-l), l); if (l == 0) ans = (ans + j*(j-1)*1LL*temp)%mod; else if (l == 1) ans = (ans + (j-1)*(j-1)*1LL*temp)%mod; else{ if (i == n) ans = (ans+temp)%mod; else ans = (ans + (j-2)*(j-1)*1LL*temp)%mod; } } // Case 2: create +1 cc // do not add an endpoint ans = (ans+solve(i+1, j+1, rem-c*(2*(j+1)-l), l))%mod; // add an endpoint ans = (ans+(2-l)*1LL*solve(i+1, j+1, rem-c*(2*(j+1)-l-1), l+1))%mod; //i think its right! // just enlarge 1 cc if (j){ // do not add an endpoint ans = (ans+(2*j-l)*1LL*solve(i+1, j, rem-c*(2*j-l), l))%mod; // add an endpoint int temp = solve(i+1, j, rem-c*(2*j-l-1), l+1); if (i == n) ans = (ans+(2-l)*j*1LL*temp)%mod; else ans = (ans+(2-l)*(j-l)*1LL*temp)%mod; } //if this is right...something else is wrong... return dp[i][j][rem][l] = ans; } int main(){ int l; scanf("%d %d", &n, &l); for (int i = 1; i <= n; i++) scanf("%d", &a[i]); sort(a+1, a+n+1); a[n+1] = a[n]; if (n == 1){ printf("1\n"); return 0; } for (int i = 1; i <= n; i++) for (int j = 0; j <= n; j++) for (int rem = 0; rem <= l; rem++) dp[i][j][rem][0] = dp[i][j][rem][1] = dp[i][j][rem][2] = -1; printf("%d\n", solve(1, 0, l, 0)); return 0; }

Compilation message (stderr)

skyscraper.cpp: In function 'int main()':
skyscraper.cpp:52:27: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d %d", &n, &l);
                           ^
skyscraper.cpp:54:27: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d", &a[i]);
                           ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...