Submission #520230

# Submission time Handle Problem Language Result Execution time Memory
520230 2022-01-28T23:59:23 Z kevin Skyscraper (JOI16_skyscraper) C++17
100 / 100
375 ms 131980 KB
#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define nl cout<<"\n"
#define ca(v) for(auto i:v) cout<<i<<" ";

const int MOD = 1e9 + 7;

ll dp[102][102][1002][3];

int main()
{
    // ios_base::sync_with_stdio(0); cin.tie(0);
    if (fopen("input.in", "r")) freopen("input.in", "r", stdin);
    int n, l;
    cin>>n>>l;
    int ar[n];
    for(int i=0; i<n; i++) cin>>ar[i];
    if(n == 1) { cout<< 1; return 0; }
    sort(ar, ar+n);
    dp[0][0][0][0] = 1;
    for(int i=0; i<n; i++){
        for(int j=0; j<n; j++){
            for(int v=0; v<=l; v++){
                for(int r=0; r<3; r++){
                    int d = ar[i] - (i?ar[i-1]:0);
                    int nx = v + d * (j * 2 - r);
                    if(nx > l || nx < 0) continue;
                    // merge 2
                    if(j) dp[i+1][j-1][nx][r] = (dp[i+1][j-1][nx][r] + dp[i][j][v][r] * (j-1) % MOD) % MOD;
                    // add to exsisting
                    dp[i+1][j][nx][r] = (dp[i+1][j][nx][r] + dp[i][j][v][r] * (2*j-r) % MOD) % MOD;
                    // cout<<i+1<<"|"<<j<<"|"<<nx<<"|"<<r<<"|"<<dp[i+1][j][nx][r];
                    // add to exsisting and -1
                    if(r<2) dp[i+1][j][nx][r+1] = (dp[i+1][j][nx][r+1] + dp[i][j][v][r] * (2-r) % MOD) % MOD;
                    // make new
                    dp[i+1][j+1][nx][r] = (dp[i+1][j+1][nx][r] + dp[i][j][v][r] * (j+1-r) % MOD) % MOD;
                    // make new and -1
                    if(r<2) dp[i+1][j+1][nx][r+1] = (dp[i+1][j+1][nx][r+1] + dp[i][j][v][r] * (2-r) % MOD) % MOD;
                }
            }
        }
    }
    int tot = 0;
    for(int i=0; i<=l; i++) tot = (tot + dp[n][1][i][2]) % MOD;
    cout<<tot;
}

Compilation message

skyscraper.cpp: In function 'int main()':
skyscraper.cpp:15:40: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   15 |     if (fopen("input.in", "r")) freopen("input.in", "r", stdin);
      |                                 ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 460 KB Output is correct
5 Correct 3 ms 1356 KB Output is correct
6 Correct 3 ms 1356 KB Output is correct
7 Correct 1 ms 588 KB Output is correct
8 Correct 1 ms 716 KB Output is correct
9 Correct 3 ms 1572 KB Output is correct
10 Correct 1 ms 716 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1100 KB Output is correct
2 Correct 1 ms 1100 KB Output is correct
3 Correct 2 ms 1356 KB Output is correct
4 Correct 2 ms 1100 KB Output is correct
5 Correct 2 ms 1228 KB Output is correct
6 Correct 2 ms 1356 KB Output is correct
7 Correct 1 ms 972 KB Output is correct
8 Correct 1 ms 1228 KB Output is correct
9 Correct 2 ms 1484 KB Output is correct
10 Correct 2 ms 1100 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 460 KB Output is correct
5 Correct 3 ms 1356 KB Output is correct
6 Correct 3 ms 1356 KB Output is correct
7 Correct 1 ms 588 KB Output is correct
8 Correct 1 ms 716 KB Output is correct
9 Correct 3 ms 1572 KB Output is correct
10 Correct 1 ms 716 KB Output is correct
11 Correct 1 ms 1100 KB Output is correct
12 Correct 1 ms 1100 KB Output is correct
13 Correct 2 ms 1356 KB Output is correct
14 Correct 2 ms 1100 KB Output is correct
15 Correct 2 ms 1228 KB Output is correct
16 Correct 2 ms 1356 KB Output is correct
17 Correct 1 ms 972 KB Output is correct
18 Correct 1 ms 1228 KB Output is correct
19 Correct 2 ms 1484 KB Output is correct
20 Correct 2 ms 1100 KB Output is correct
21 Correct 4 ms 4428 KB Output is correct
22 Correct 349 ms 130400 KB Output is correct
23 Correct 355 ms 123300 KB Output is correct
24 Correct 352 ms 127644 KB Output is correct
25 Correct 375 ms 128684 KB Output is correct
26 Correct 337 ms 119136 KB Output is correct
27 Correct 141 ms 76152 KB Output is correct
28 Correct 181 ms 89488 KB Output is correct
29 Correct 324 ms 131980 KB Output is correct
30 Correct 366 ms 126184 KB Output is correct