답안 #751019

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
751019 2023-05-30T19:37:50 Z Sami_Massah Skyscraper (JOI16_skyscraper) C++17
100 / 100
127 ms 5816 KB
#include <bits/stdc++.h>
using namespace std;


const long long maxn = 100 + 12, maxk = 3000, inf = 1001, mod = 1e9 + 7;
long long n, mx, a[maxn], dp[2][maxn][maxk][3];
int main(){
    cin >> n >> mx;

    for(int i = 0; i < n; i++){
        cin >> a[i];
      //  a[i] = i * 2 + 1;
        }
    if(n == 1){
        cout << 1 << endl;
        return 0;

    }
    sort(a, a + n);
    for(int i = n; i >= 1; i--)
        swap(a[i], a[i - 1]);
    a[n + 1] = inf;
   //cout << a[1] << ' ' << a[2] << endl;
    dp[0][0][0][0] = 1;
    for(int i = 1; i <= n; i++)
        for(int j = 1; j <= n; j++)
            for(int c = 0; c <= mx; c++)
                for(int m = 0; m <= 2; m++){
                    int delta = (2 * j - m) * (a[i + 1] - a[i]);
                    dp[i & 1][j][c][m] = 0;
                    if(i == 2)
                        dp[0][0][0][0] = 0;
                    if(delta > c)
                        continue;

                    dp[i & 1][j][c][m] += dp[i & 1 ^ 1][j - 1][c - delta][m] * (j - m);

                    if(m > 0){

                        dp[i & 1][j][c][m] += dp[i & 1 ^ 1][j - 1][c - delta][m - 1] * (2 - (m - 1));
                    }

                    dp[i & 1][j][c][m] += dp[i & 1 ^ 1][j][c - delta][m] * (2 * j - m);

                    if(m > 0)
                        dp[i & 1][j][c][m] += dp[i & 1 ^ 1][j][c - delta][m - 1] * (3 - m);

                    dp[i & 1][j][c][m] += dp[i & 1 ^ 1][j + 1][c - delta][m] * (j);
                    dp[i & 1][j][c][m] %= mod;
                //   cout << i << ' ' << j + 1 << ' ' << c- delta << ' ' << m <<' ' << dp[i][j + 1][c - delta][m] << endl << endl;
                }
    long long ans = 0;
    for(int c = 1; c <= mx; c++){
        ans += dp[n & 1][1][c][2];
        ans %= mod;
    }
    cout << ans << endl;

}

Compilation message

skyscraper.cpp: In function 'int main()':
skyscraper.cpp:36:48: warning: suggest parentheses around arithmetic in operand of '^' [-Wparentheses]
   36 |                     dp[i & 1][j][c][m] += dp[i & 1 ^ 1][j - 1][c - delta][m] * (j - m);
      |                                              ~~^~~
skyscraper.cpp:40:52: warning: suggest parentheses around arithmetic in operand of '^' [-Wparentheses]
   40 |                         dp[i & 1][j][c][m] += dp[i & 1 ^ 1][j - 1][c - delta][m - 1] * (2 - (m - 1));
      |                                                  ~~^~~
skyscraper.cpp:43:48: warning: suggest parentheses around arithmetic in operand of '^' [-Wparentheses]
   43 |                     dp[i & 1][j][c][m] += dp[i & 1 ^ 1][j][c - delta][m] * (2 * j - m);
      |                                              ~~^~~
skyscraper.cpp:46:52: warning: suggest parentheses around arithmetic in operand of '^' [-Wparentheses]
   46 |                         dp[i & 1][j][c][m] += dp[i & 1 ^ 1][j][c - delta][m - 1] * (3 - m);
      |                                                  ~~^~~
skyscraper.cpp:48:48: warning: suggest parentheses around arithmetic in operand of '^' [-Wparentheses]
   48 |                     dp[i & 1][j][c][m] += dp[i & 1 ^ 1][j + 1][c - delta][m] * (j);
      |                                              ~~^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 724 KB Output is correct
6 Correct 1 ms 596 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 316 KB Output is correct
9 Correct 1 ms 724 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 468 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 468 KB Output is correct
5 Correct 1 ms 468 KB Output is correct
6 Correct 1 ms 468 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 468 KB Output is correct
10 Correct 1 ms 468 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 724 KB Output is correct
6 Correct 1 ms 596 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 316 KB Output is correct
9 Correct 1 ms 724 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 468 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 468 KB Output is correct
15 Correct 1 ms 468 KB Output is correct
16 Correct 1 ms 468 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 468 KB Output is correct
20 Correct 1 ms 468 KB Output is correct
21 Correct 1 ms 724 KB Output is correct
22 Correct 101 ms 3924 KB Output is correct
23 Correct 125 ms 5728 KB Output is correct
24 Correct 105 ms 4604 KB Output is correct
25 Correct 127 ms 5716 KB Output is correct
26 Correct 110 ms 5088 KB Output is correct
27 Correct 36 ms 2260 KB Output is correct
28 Correct 48 ms 2528 KB Output is correct
29 Correct 91 ms 3840 KB Output is correct
30 Correct 121 ms 5816 KB Output is correct