답안 #551780

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
551780 2022-04-21T14:14:25 Z Killer2501 Skyscraper (JOI16_skyscraper) C++14
100 / 100
1259 ms 189436 KB
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define ull unsigned long long
#define pb push_back
#define pll pair<int, pii>
#define pii pair<int, int>
#define fi first
#define se second
using namespace std;
const int N = 1e2+5;
const int M = N*100;
const int mod = 1e9+7;
const int base = 75;
const ll inf = 1e12;
int n, t, tong;
int k, m, a[N], b[N], dp[N][N][M][3];
int ans, d[N];
void add(int& x, int y)
{
    x += y;
    if(x >= mod)x -= mod;
}
void sol()
{
    cin >> n >> k;
    for(int i = 1; i <= n; i ++)cin >> a[i], b[i] = i;
    if(n == 1)
    {
        cout << 1 << '\n';
        return;
    }
    sort(a+1, a+1+n);
    reverse(a+1, a+1+n);
    dp[1][1][a[1]*2][0] = 1;
    dp[1][1][a[1]][1] = 2;
    for(int i = 1; i <= n; i ++)
    {
        for(int j = 1; j <= i; j ++)
        {
            for(int p = 0; p < M; p ++)
            {
                for(int q = 0; q < 3; q ++)
                {
                    if(dp[i][j][p][q] == 0)continue;
                    if(p+a[i+1]*2 < M)add(dp[i+1][j+1][p+a[i+1]*2][q], 1ll*dp[i][j][p][q]*(j+1-q)%mod);
                    if(q < 2 && p+a[i+1] < M)add(dp[i+1][j+1][p+a[i+1]][q+1], 1ll*dp[i][j][p][q]*(2-q)%mod);
                    add(dp[i+1][j][p][q], 1ll*dp[i][j][p][q]*(2*j-q)%mod);
                    if(q < 2 && p >= a[i+1])add(dp[i+1][j][p-a[i+1]][q+1], 1ll*dp[i][j][p][q]*(2-q)%mod);
                    if(j > 1 && p >= a[i+1]*2)add(dp[i+1][j-1][p-a[i+1]*2][q], 1ll*dp[i][j][p][q]*(j-1)%mod);
                }
            }
        }
    }
    for(int i = 0; i <= k; i ++)add(ans, dp[n][1][i][2]);
    cout << ans << '\n';
}
int main()
{
    cin.tie(0);
    cout.tie(0);
    ios_base::sync_with_stdio(0);
    #define task "test"
    if(fopen(task".inp", "r"))
	{
		freopen(task".inp", "r", stdin);
		freopen(task".out", "w", stdout);
	}
    int test = 1;
    //cin >> test;
    while(test -- > 0)sol();
    return 0;
}

Compilation message

skyscraper.cpp: In function 'int main()':
skyscraper.cpp:66:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   66 |   freopen(task".inp", "r", stdin);
      |   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
skyscraper.cpp:67:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   67 |   freopen(task".out", "w", stdout);
      |   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 3 ms 588 KB Output is correct
5 Correct 5 ms 2260 KB Output is correct
6 Correct 6 ms 2004 KB Output is correct
7 Correct 3 ms 852 KB Output is correct
8 Correct 3 ms 596 KB Output is correct
9 Correct 5 ms 1748 KB Output is correct
10 Correct 3 ms 596 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 724 KB Output is correct
2 Correct 10 ms 1492 KB Output is correct
3 Correct 7 ms 996 KB Output is correct
4 Correct 9 ms 1492 KB Output is correct
5 Correct 9 ms 1620 KB Output is correct
6 Correct 8 ms 1320 KB Output is correct
7 Correct 9 ms 1108 KB Output is correct
8 Correct 7 ms 976 KB Output is correct
9 Correct 8 ms 1004 KB Output is correct
10 Correct 11 ms 1520 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 3 ms 588 KB Output is correct
5 Correct 5 ms 2260 KB Output is correct
6 Correct 6 ms 2004 KB Output is correct
7 Correct 3 ms 852 KB Output is correct
8 Correct 3 ms 596 KB Output is correct
9 Correct 5 ms 1748 KB Output is correct
10 Correct 3 ms 596 KB Output is correct
11 Correct 5 ms 724 KB Output is correct
12 Correct 10 ms 1492 KB Output is correct
13 Correct 7 ms 996 KB Output is correct
14 Correct 9 ms 1492 KB Output is correct
15 Correct 9 ms 1620 KB Output is correct
16 Correct 8 ms 1320 KB Output is correct
17 Correct 9 ms 1108 KB Output is correct
18 Correct 7 ms 976 KB Output is correct
19 Correct 8 ms 1004 KB Output is correct
20 Correct 11 ms 1520 KB Output is correct
21 Correct 81 ms 8836 KB Output is correct
22 Correct 650 ms 91288 KB Output is correct
23 Correct 623 ms 71332 KB Output is correct
24 Correct 913 ms 113036 KB Output is correct
25 Correct 647 ms 75084 KB Output is correct
26 Correct 744 ms 88984 KB Output is correct
27 Correct 1236 ms 182636 KB Output is correct
28 Correct 1231 ms 182736 KB Output is correct
29 Correct 1259 ms 189436 KB Output is correct
30 Correct 556 ms 70368 KB Output is correct