Submission #938846

#TimeUsernameProblemLanguageResultExecution timeMemory
938846HanksburgerSkyscraper (JOI16_skyscraper)C++17
100 / 100
524 ms166624 KiB
#include <bits/stdc++.h> using namespace std; vector<pair<long long, long long> > dp[105][55][5]; long long a[105], n, m, ans, mod=1e9+7; void f(long long x, long long y, long long z) { for (pair<long long, long long> p:dp[x][y][z]) { dp[x+1][y+1][z].push_back({p.first+(a[x+1]-a[x])*((y+1)*2+z), p.second}); dp[x+1][y][z+1].push_back({p.first+(a[x+1]-a[x])*(y*2+z+1), p.second}); if (y || z) dp[x+1][y][z].push_back({p.first+(a[x+1]-a[x])*(y*2+z), p.second*(y*2+z)%mod}); if (y && z) dp[x+1][y-1][z].push_back({p.first+(a[x+1]-a[x])*((y-1)*2+z), p.second*y%mod*z%mod}); if (y) dp[x+1][y-1][z+1].push_back({p.first+(a[x+1]-a[x])*(y*2+z-1), p.second*y%mod}); if (y>=2) dp[x+1][y-1][z].push_back({p.first+(a[x+1]-a[x])*((y-1)*2+z), p.second*y%mod*(y-1)%mod}); } } void g(long long x, long long y, long long z) { sort(dp[x][y][z].begin(), dp[x][y][z].end()); vector<pair<long long, long long> > tmp; long long sum=0; for (long long i=0; i<dp[x][y][z].size(); i++) { sum=(sum+dp[x][y][z][i].second)%mod; if (i==(long long)dp[x][y][z].size()-1 || dp[x][y][z][i].first<dp[x][y][z][i+1].first) { if (dp[x][y][z][i].first<=m) tmp.push_back({dp[x][y][z][i].first, sum}); sum=0; } } dp[x][y][z]=tmp; } int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> n >> m; if (n==1) { cout << 1; return 0; } for (long long i=1; i<=n; i++) cin >> a[i]; sort(a+1, a+n+1); dp[1][0][0].push_back({0, 1}); f(1, 0, 0); for (long long i=2; i<n; i++) { for (long long j=0; j<=50; j++) { for (long long k=0; k<=2; k++) { g(i, j, k); f(i, j, k); } } } g(n, 0, 1); g(n, 0, 2); for (long long i=0; i<dp[n][0][1].size(); i++) ans=(ans+dp[n][0][1][i].second)%mod; for (long long i=0; i<dp[n][0][2].size(); i++) ans=(ans+dp[n][0][2][i].second)%mod; cout << ans*2%mod; }

Compilation message (stderr)

skyscraper.cpp: In function 'void g(long long int, long long int, long long int)':
skyscraper.cpp:26:26: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   26 |     for (long long i=0; i<dp[x][y][z].size(); i++)
      |                         ~^~~~~~~~~~~~~~~~~~~
skyscraper.cpp: In function 'int main()':
skyscraper.cpp:67:26: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   67 |     for (long long i=0; i<dp[n][0][1].size(); i++)
      |                         ~^~~~~~~~~~~~~~~~~~~
skyscraper.cpp:69:26: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   69 |     for (long long i=0; i<dp[n][0][2].size(); i++)
      |                         ~^~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...