답안 #152953

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
152953 2019-09-10T16:40:53 Z Mercenary Skyscraper (JOI16_skyscraper) C++14
100 / 100
240 ms 48500 KB
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/trie_policy.hpp>

#define pb push_back
#define mp make_pair
#define taskname "A"

using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
typedef long double ld;
typedef pair<int,int> ii;
typedef tree <int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;

const int maxn = 105 + 5;
const int maxl = 1005;

const int mod = 1e9 + 7;

int a[maxn] , n , l;
int dp[maxn][maxn][maxl][3];

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    if(fopen(taskname".INP","r")){
		freopen(taskname".INP", "r",stdin);
		freopen(taskname".OUT", "w",stdout);
    }
    cin >> n >> l;
    for(int i= 1 ; i <= n ; ++i)cin >> a[i];
    sort(a + 1 , a + n + 1);
    for(int i = n ; i >= 1 ; --i)a[i] -= a[i - 1];
    if(n == 1)return cout << 1 , 0;
    dp[1][1][0][0] = 1;
    dp[1][1][0][1] = 2;
    for(int i = 1 ; i < n ; ++i){
        a[i] = a[i + 1];
        for(int j = 1 ; j <= i ; ++j){
            for(int t = 0 ; t <= l ; ++t){
                auto add = [&] (int i , int j , int t , int k , int val){
//                    assert(val >= 0);
                    if(t <= l){
                        dp[i][j][t][k] += val;
//                        cout << i << " " << j << " " << t << " " << k << " " << dp[i][j][t][k] << endl;
                        if(dp[i][j][t][k] >= mod)dp[i][j][t][k] -= mod;
                    }
                };
                add(i + 1 , j + 1 , t + 2 * j * a[i] , 1 , 2 * dp[i][j][t][0] % mod);//add end or start
                add(i + 1 , j , t + 2 * j * a[i] , 1 , (ll)2 * j * dp[i][j][t][0] % mod);//add end or start and connect to 1 component
                if(i + 1 < n)add(i + 1 , j + 1 , t + 2 * j * a[i] , 0 , dp[i][j][t][0]);
                add(i + 1 , j , t + 2 * j * a[i] , 0 , 2ll * j * dp[i][j][t][0] % mod);
                if(j >= 2)add(i + 1 , j - 1 , t + 2 * j * a[i] , 0 , (ll)j * (j - 1) % mod * dp[i][j][t][0] % mod);

                add(i + 1 , j + 1 , t + (2 * j - 1) * a[i] , 2 , dp[i][j][t][1]);
                if(j > 1)add(i + 1 , j , t + (2 * j - 1) * a[i] , 2 , (ll)(j - 1) * dp[i][j][t][1] % mod);
                add(i + 1 , j , t + (2 * j - 1) * a[i] , 1 , dp[i][j][t][1]);
                add(i + 1 , j - 1 , t + (2 * j - 1) * a[i] , 1 , 1ll * (j - 1) * dp[i][j][t][1] % mod);
                if(i + 1 < n)add(i + 1 , j + 1 , t + (2 * j - 1) * a[i] , 1 , dp[i][j][t][1]);
                if(j >= 1)add(i + 1 , j , t + (2 * j - 1) * a[i] , 1 , 2ll * (j - 1) * dp[i][j][t][1] % mod);
                if(j >= 3)add(i + 1 , j - 1 , t + (2 * j - 1) * a[i] , 1 , (ll)(j - 1) * (j - 2) % mod * dp[i][j][t][1] % mod);

                if(i + 1 < n)add(i + 1 , j + 1 , t + (2 * j - 2) * a[i] , 2 , dp[i][j][t][2]);
                add(i + 1 , j , t + (2 * j - 2) * a[i] , 2 , 2 * dp[i][j][t][2] % mod);
                add(i + 1 , j - 1, t + (2 * j - 2) * a[i] , 2 , 2ll * (j - 2) * dp[i][j][t][2] % mod);
                if(j >= 2)add(i + 1 , j , t + (2 * j - 2) * a[i] , 2 , 2ll * (j - 2) * dp[i][j][t][2] % mod);
                if(j >= 4)add(i + 1 , j - 1 , t + (2 * j - 2) * a[i] , 2 , (ll)(j - 2) * (j - 3) % mod * dp[i][j][t][2] % mod);
            }
        }
    }
    for(int i = 2 ; i <= n ; ++i){
        for(int j = 1 ; j <= i ; ++j){
            for(int t = 0 ; t <= l ; ++t){
//                cout << i << " " << j << " " << t << " " << dp[i][j][t][0] << " " << dp[i][j][t][1] << " " << dp[i][j][t][2] << endl;
            }
        }
    }
    int res = 0;
    for(int i = 1 ; i <= l ; ++i){
        if(i - 2 * a[n] >= 0){
            res += dp[n - 1][2][i - 2 * a[n]][2];
            if(res >= mod)res -= mod;
        }
        if(i - a[n] >= 0){
            res += dp[n - 1][1][i - a[n]][1] % mod;
            if(res >= mod)res -= mod;
        }
    }
//    cerr << dp[n][1][l][2];
    cout << res;
}

Compilation message

skyscraper.cpp: In function 'int main()':
skyscraper.cpp:30:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
   freopen(taskname".INP", "r",stdin);
   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
skyscraper.cpp:31:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
   freopen(taskname".OUT", "w",stdout);
   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 504 KB Output is correct
3 Correct 2 ms 380 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 4 ms 888 KB Output is correct
6 Correct 3 ms 760 KB Output is correct
7 Correct 3 ms 504 KB Output is correct
8 Correct 3 ms 504 KB Output is correct
9 Correct 4 ms 888 KB Output is correct
10 Correct 3 ms 632 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 760 KB Output is correct
2 Correct 3 ms 760 KB Output is correct
3 Correct 3 ms 888 KB Output is correct
4 Correct 4 ms 760 KB Output is correct
5 Correct 3 ms 888 KB Output is correct
6 Correct 3 ms 1016 KB Output is correct
7 Correct 3 ms 760 KB Output is correct
8 Correct 3 ms 888 KB Output is correct
9 Correct 3 ms 1016 KB Output is correct
10 Correct 3 ms 768 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 504 KB Output is correct
3 Correct 2 ms 380 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 4 ms 888 KB Output is correct
6 Correct 3 ms 760 KB Output is correct
7 Correct 3 ms 504 KB Output is correct
8 Correct 3 ms 504 KB Output is correct
9 Correct 4 ms 888 KB Output is correct
10 Correct 3 ms 632 KB Output is correct
11 Correct 3 ms 760 KB Output is correct
12 Correct 3 ms 760 KB Output is correct
13 Correct 3 ms 888 KB Output is correct
14 Correct 4 ms 760 KB Output is correct
15 Correct 3 ms 888 KB Output is correct
16 Correct 3 ms 1016 KB Output is correct
17 Correct 3 ms 760 KB Output is correct
18 Correct 3 ms 888 KB Output is correct
19 Correct 3 ms 1016 KB Output is correct
20 Correct 3 ms 768 KB Output is correct
21 Correct 7 ms 3364 KB Output is correct
22 Correct 206 ms 37568 KB Output is correct
23 Correct 234 ms 45256 KB Output is correct
24 Correct 221 ms 48440 KB Output is correct
25 Correct 238 ms 45112 KB Output is correct
26 Correct 213 ms 44116 KB Output is correct
27 Correct 100 ms 32116 KB Output is correct
28 Correct 122 ms 35448 KB Output is correct
29 Correct 211 ms 48500 KB Output is correct
30 Correct 240 ms 45176 KB Output is correct