답안 #727000

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
727000 2023-04-19T19:19:48 Z sochu Skyscraper (JOI16_skyscraper) C++14
0 / 100
3 ms 340 KB
#include <bits/stdc++.h>
//#pragma GCC optimize ("03")
#define FastIO ios_base::sync_with_stdio(false) , cin.tie(0) , cout.tie(0)
#define FILES freopen("in" , "r" , stdin) , freopen("out" , "w" , stdout)
#define ll long long
#define ull unsigned long long
#define ld long double
#define eb emplace_back
#define pb push_back
#define qwerty1 first
#define qwerty2 second
#define qwerty3 -> first
#define qwerty4 -> second
#define umap unordered_map
#define uset unordered_set
#define pii pair < ll , ll >
#define pq priority_queue
#define dbg(x) cerr << #x << ": " << x << '\n'

namespace FastRead
{
    char __buff[5000];ll __lg = 0 , __p = 0;
    char nc()
    {
        if(__lg == __p){__lg = fread(__buff , 1 , 5000 , stdin);__p = 0;if(!__lg) return EOF;}
        return __buff[__p++];
    }
    template<class T>void read(T&__x)
    {
        T __sgn = 1; char __c;while(!isdigit(__c = nc()))if(__c == '-')__sgn = -1;
        __x = __c - '0';while(isdigit(__c = nc()))__x = __x * 10 + __c - '0';__x *= __sgn;
    }
}

using namespace FastRead;
using namespace std;

const ll N = 1e2 + 10;
const ll L = 1e3 + 10;
const ll M = 1e9 + 7;
const ld PI = acos(-1);
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

int n , l;
int a[N] , dp[N][N][L * 3][4];

void add(int &x , int y)
{
    if(y >= M) y %= M;
    x += y;
    if(x >= M) x -= M;
}

signed main()
{
	#ifndef ONLINE_JUDGE
		FastIO , FILES;
	#endif

	int i , j , s;

    cin >> n >> l;

    for(i = 1 ; i <= n ; i++)
        cin >> a[i];

    sort(a + 1 , a + n + 1);

    dp[1][1][0 + L][0] = 1;
    dp[1][1][-a[1] + L][1] = 1;
    dp[1][1][-a[1] + L][2] = 1;
    dp[1][1][-(2 * a[1]) + L][3] = 1;

    for(i = 2 ; i <= n ; i++)
    {
        for(j = 1 ; j <= i ; j++)
        {
            for(s = -l ; s <= l ; s++)
            {
                ///merge
                if(s - 2 * a[i] + L >= 0)
                {
                    add(dp[i][j][s + L][0] , j * dp[i - 1][j + 1][s - 2 * a[i] + L][0]);
                    add(dp[i][j][s + L][1] , j * dp[i - 1][j + 1][s - 2 * a[i] + L][1]);
                    add(dp[i][j][s + L][2] , j * dp[i - 1][j + 1][s - 2 * a[i] + L][2]);
                    add(dp[i][j][s + L][3] , j * dp[i - 1][j + 1][s - 2 * a[i] + L][3]);
                }

                ///concat
                add(dp[i][j][s + L][0] , (2 * j - 2) * dp[i - 1][j][s + L][0]);
                add(dp[i][j][s + L][1] , (2 * j - 2) * dp[i - 1][j][s + L][1]);
                add(dp[i][j][s + L][2] , (2 * j - 2) * dp[i - 1][j][s + L][2]);
                add(dp[i][j][s + L][3] , (2 * j - 2) * dp[i - 1][j][s + L][3]);


                if(s - a[i] + L >= 0) add(dp[i][j][s + L][0] , dp[i - 1][j][s - a[i] + L][1]);
                                      add(dp[i][j][s + L][2] , dp[i - 1][j][s - a[i] + L][3]);
                                      add(dp[i][j][s + L][1] , dp[i - 1][j][s        + L][1]);
                                      add(dp[i][j][s + L][3] , dp[i - 1][j][s        + L][3]);
                                     // add(dp[i][j][s + L][3] , dp[i - 1][j][s        + L][1]);

                if(s - a[i] + L >= 0) add(dp[i][j][s + L][0] , dp[i - 1][j][s - a[i] + L][2]);
                                      add(dp[i][j][s + L][2] , dp[i - 1][j][s        + L][2]);
                                      add(dp[i][j][s + L][3] , dp[i - 1][j][s        + L][3]);
                                      add(dp[i][j][s + L][1] , dp[i - 1][j][s - a[i] + L][3]);
                                     // add(dp[i][j][s + L][3] , dp[i - 1][j][s        + L][2]);


                ///new
                if(j > 2 && s + 2 * a[i] + L >= 0)
                {
                    add(dp[i][j][s + L][0] , (j - 2) * dp[i - 1][j - 1][s + 2 * a[i] + L][0]);
                    add(dp[i][j][s + L][1] , (j - 2) * dp[i - 1][j - 1][s + 2 * a[i] + L][1]);
                    add(dp[i][j][s + L][2] , (j - 2) * dp[i - 1][j - 1][s + 2 * a[i] + L][2]);
                    add(dp[i][j][s + L][3] , (j - 2) * dp[i - 1][j - 1][s + 2 * a[i] + L][3]);
                }

                if(s + a[i] + L >= 0) add(dp[i][j][s + L][0] , dp[i - 1][j - 1][s +     a[i] + L][1]);
                if(s + a[i] + L >= 0) add(dp[i][j][s + L][0] , dp[i - 1][j - 1][s +     a[i] + L][2]);
                                      add(dp[i][j][s + L][1] , dp[i - 1][j - 1][s + 2 * a[i] + L][1]);
                                      add(dp[i][j][s + L][2] , dp[i - 1][j - 1][s + 2 * a[i] + L][2]);
                                      add(dp[i][j][s + L][3] , dp[i - 1][j - 1][s + 2 * a[i] + L][3]);
                                      add(dp[i][j][s + L][3] , dp[i - 1][j - 1][s + 2 * a[i] + L][3]);
                                      add(dp[i][j][s + L][2] , dp[i - 1][j - 1][s +     a[i] + L][3]);
                                      add(dp[i][j][s + L][1] , dp[i - 1][j - 1][s +     a[i] + L][3]);

            }
        }
    }

    int ans = 0;

    for(int s = 0 ; s <= l ; s++)
        add(ans , dp[n][1][s + L][0]);

    cout << ans;

    return 0;
}

Compilation message

skyscraper.cpp: In function 'int main()':
skyscraper.cpp:96:17: warning: this 'if' clause does not guard... [-Wmisleading-indentation]
   96 |                 if(s - a[i] + L >= 0) add(dp[i][j][s + L][0] , dp[i - 1][j][s - a[i] + L][1]);
      |                 ^~
skyscraper.cpp:97:39: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'if'
   97 |                                       add(dp[i][j][s + L][2] , dp[i - 1][j][s - a[i] + L][3]);
      |                                       ^~~
skyscraper.cpp:102:17: warning: this 'if' clause does not guard... [-Wmisleading-indentation]
  102 |                 if(s - a[i] + L >= 0) add(dp[i][j][s + L][0] , dp[i - 1][j][s - a[i] + L][2]);
      |                 ^~
skyscraper.cpp:103:39: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'if'
  103 |                                       add(dp[i][j][s + L][2] , dp[i - 1][j][s        + L][2]);
      |                                       ^~~
skyscraper.cpp:119:17: warning: this 'if' clause does not guard... [-Wmisleading-indentation]
  119 |                 if(s + a[i] + L >= 0) add(dp[i][j][s + L][0] , dp[i - 1][j - 1][s +     a[i] + L][2]);
      |                 ^~
skyscraper.cpp:120:39: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'if'
  120 |                                       add(dp[i][j][s + L][1] , dp[i - 1][j - 1][s + 2 * a[i] + L][1]);
      |                                       ^~~
skyscraper.cpp:4:22: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
    4 | #define FILES freopen("in" , "r" , stdin) , freopen("out" , "w" , stdout)
      |               ~~~~~~~^~~~~~~~~~~~~~~~~~~~
skyscraper.cpp:57:12: note: in expansion of macro 'FILES'
   57 |   FastIO , FILES;
      |            ^~~~~
skyscraper.cpp:4:52: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
    4 | #define FILES freopen("in" , "r" , stdin) , freopen("out" , "w" , stdout)
      |                                             ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
skyscraper.cpp:57:12: note: in expansion of macro 'FILES'
   57 |   FastIO , FILES;
      |            ^~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 3 ms 340 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 340 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 3 ms 340 KB Output isn't correct
2 Halted 0 ms 0 KB -