답안 #751018

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
751018 2023-05-30T19:32:13 Z Sami_Massah Skyscraper (JOI16_skyscraper) C++17
15 / 100
1 ms 468 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;
        }
    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 = 1; 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:31:48: warning: suggest parentheses around arithmetic in operand of '^' [-Wparentheses]
   31 |                     dp[i & 1][j][c][m] += dp[i & 1 ^ 1][j - 1][c - delta][m] * (j - m);
      |                                              ~~^~~
skyscraper.cpp:35:52: warning: suggest parentheses around arithmetic in operand of '^' [-Wparentheses]
   35 |                         dp[i & 1][j][c][m] += dp[i & 1 ^ 1][j - 1][c - delta][m - 1] * (2 - (m - 1));
      |                                                  ~~^~~
skyscraper.cpp:38:48: warning: suggest parentheses around arithmetic in operand of '^' [-Wparentheses]
   38 |                     dp[i & 1][j][c][m] += dp[i & 1 ^ 1][j][c - delta][m] * (2 * j - m);
      |                                              ~~^~~
skyscraper.cpp:41:52: warning: suggest parentheses around arithmetic in operand of '^' [-Wparentheses]
   41 |                         dp[i & 1][j][c][m] += dp[i & 1 ^ 1][j][c - delta][m - 1] * (3 - m);
      |                                                  ~~^~~
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 + 1][c - delta][m] * (j);
      |                                              ~~^~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 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 408 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 Incorrect 0 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -