답안 #727023

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
727023 2023-04-19T20:28:29 Z sochu Skyscraper (JOI16_skyscraper) C++14
20 / 100
1513 ms 55552 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 = 4e3 + 10;
const ll M = 1e9 + 7;
const ld PI = acos(-1);
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

ll n , l;
ll a[N];
//array < array < array < ll , 4 >  , 2 * L > , N > dp1 , dp_old;
ll curr_dp[N][2 * L][4] , old_dp[N][2 * L][4];

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

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

	ll i , j , s;

    cin >> n >> l;

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

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

    old_dp[1][0 + L][0] = 1;
    old_dp[1][-a[1] + L][1] = 1;
    old_dp[1][-a[1] + L][2] = 1;
    old_dp[1][-2 * a[1] + L][3] = 1;

    for(i = 2 ; i <= n ; i++)
    {
        for(j = 1 ; j <= i ; j++)
        {
            for(s = -4 * l ; s <= 2 * l ; s++)
            {
                curr_dp[j][s + L][0] = curr_dp[j][s + L][1] = curr_dp[j][s + L][2] = curr_dp[j][s + L][3] = 0;

                ///merge
                if(s - 2 * a[i] + L >= 0)
                {
                    add(curr_dp[j][s + L][0] , 1ll * j * old_dp[j + 1][s - 2 * a[i] + L][0]);
                    add(curr_dp[j][s + L][1] , 1ll * j * old_dp[j + 1][s - 2 * a[i] + L][1]);
                    add(curr_dp[j][s + L][2] , 1ll * j * old_dp[j + 1][s - 2 * a[i] + L][2]);
                    add(curr_dp[j][s + L][3] , 1ll * j * old_dp[j + 1][s - 2 * a[i] + L][3]);
                }

                ///concat
                add(curr_dp[j][s + L][0] , 1ll * (2 * j - 2) * old_dp[j][s + L][0]);
                add(curr_dp[j][s + L][1] , 1ll * (2 * j - 2) * old_dp[j][s + L][1]);
                add(curr_dp[j][s + L][2] , 1ll * (2 * j - 2) * old_dp[j][s + L][2]);
                add(curr_dp[j][s + L][3] , 1ll * (2 * j - 2) * old_dp[j][s + L][3]);


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

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


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

                if(s + a[i] + L < 2 * L) add(curr_dp[j][s + L][0] , old_dp[j - 1][s +     a[i] + L][1]);
                if(s + a[i] + L < 2 * L) add(curr_dp[j][s + L][0] , old_dp[j - 1][s +     a[i] + L][2]);
                if(s + 2 * a[i] + L < 2 * L) add(curr_dp[j][s + L][1] , old_dp[j - 1][s + 2 * a[i] + L][1]);
                if(s + 2 * a[i] + L < 2 * L)                      add(curr_dp[j][s + L][2] , old_dp[j - 1][s + 2 * a[i] + L][2]);
                if(s + 2 * a[i] + L < 2 * L)                    add(curr_dp[j][s + L][3] , old_dp[j - 1][s + 2 * a[i] + L][3]);
                 if(s + 2 * a[i] + L < 2 * L)                     add(curr_dp[j][s + L][3] , old_dp[j - 1][s + 2 * a[i] + L][3]);
                 if(s + a[i] + L < 2 * L)     add(curr_dp[j][s + L][2] , old_dp[j - 1][s +     a[i] + L][3]);
                  if(s + a[i] + L < 2 * L)    add(curr_dp[j][s + L][1] , old_dp[j - 1][s +     a[i] + L][3]);

            }
        }

       swap(curr_dp , old_dp);
       //memset(curr_dp , 0 , sizeof curr_dp);
    }

    ll ans = 0;

    for(ll s = 0 ; s <= l ; s++)
        add(ans , old_dp[1][s + L][0]);

    cout << ans;
    return 0;
}

Compilation message

skyscraper.cpp: In function 'int main()':
skyscraper.cpp:101:17: warning: this 'if' clause does not guard... [-Wmisleading-indentation]
  101 |                 if(s - a[i] + L >= 0) add(curr_dp[j][s + L][2] , old_dp[j][s - a[i] + L][3]);
      |                 ^~
skyscraper.cpp:102:39: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'if'
  102 |                                       add(curr_dp[j][s + L][1] , old_dp[j][s        + L][1]);
      |                                       ^~~
skyscraper.cpp:106:17: warning: this 'if' clause does not guard... [-Wmisleading-indentation]
  106 |                 if(s - a[i] + L >= 0) add(curr_dp[j][s + L][0] , old_dp[j][s - a[i] + L][2]);
      |                 ^~
skyscraper.cpp:107:39: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'if'
  107 |                                       add(curr_dp[j][s + L][2] , old_dp[j][s        + L][2]);
      |                                       ^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 33 ms 55504 KB Output is correct
3 Correct 38 ms 55548 KB Output is correct
4 Correct 57 ms 55432 KB Output is correct
5 Correct 72 ms 55532 KB Output is correct
6 Correct 68 ms 55532 KB Output is correct
7 Correct 63 ms 55528 KB Output is correct
8 Correct 65 ms 55528 KB Output is correct
9 Correct 67 ms 55528 KB Output is correct
10 Correct 69 ms 55500 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 95 ms 55528 KB Output is correct
2 Correct 94 ms 55440 KB Output is correct
3 Correct 106 ms 55552 KB Output is correct
4 Correct 94 ms 55544 KB Output is correct
5 Correct 120 ms 55464 KB Output is correct
6 Correct 106 ms 55524 KB Output is correct
7 Correct 93 ms 55536 KB Output is correct
8 Correct 92 ms 55532 KB Output is correct
9 Correct 106 ms 55528 KB Output is correct
10 Correct 111 ms 55512 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 33 ms 55504 KB Output is correct
3 Correct 38 ms 55548 KB Output is correct
4 Correct 57 ms 55432 KB Output is correct
5 Correct 72 ms 55532 KB Output is correct
6 Correct 68 ms 55532 KB Output is correct
7 Correct 63 ms 55528 KB Output is correct
8 Correct 65 ms 55528 KB Output is correct
9 Correct 67 ms 55528 KB Output is correct
10 Correct 69 ms 55500 KB Output is correct
11 Correct 95 ms 55528 KB Output is correct
12 Correct 94 ms 55440 KB Output is correct
13 Correct 106 ms 55552 KB Output is correct
14 Correct 94 ms 55544 KB Output is correct
15 Correct 120 ms 55464 KB Output is correct
16 Correct 106 ms 55524 KB Output is correct
17 Correct 93 ms 55536 KB Output is correct
18 Correct 92 ms 55532 KB Output is correct
19 Correct 106 ms 55528 KB Output is correct
20 Correct 111 ms 55512 KB Output is correct
21 Correct 238 ms 55536 KB Output is correct
22 Correct 939 ms 55540 KB Output is correct
23 Correct 1513 ms 55528 KB Output is correct
24 Incorrect 1294 ms 55536 KB Output isn't correct
25 Halted 0 ms 0 KB -