답안 #40733

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
40733 2018-02-07T16:47:18 Z Alexa2001 Skyscraper (JOI16_skyscraper) C++14
100 / 100
468 ms 4068 KB
#include <bits/stdc++.h>

using namespace std;

const int Nmax = 103, Kmax = 1003;
const int Mod = 1e9 + 7;
typedef long long ll;

int N, K, i, j, k, F, S, new_k, a[Nmax];
int now[Nmax][Kmax][2][2], old[Nmax][Kmax][2][2];

void add_to(int &x, int y, int z)
{
    x = (x + (ll)y*z) % Mod;
}

int main()
{
    // freopen("input", "r", stdin);

    cin >> N >> K;
    for(i=1; i<=N; ++i) cin >> a[i];
    sort(a+1, a+N+1);
    for(i=1; i<N; ++i) a[i] = a[i+1] - a[i];

    now[0][0][1][1] = now[0][0][0][1] = now[0][0][1][0] = now[0][0][0][0] = 1;
    for(i=1; i<N; ++i)
    {
        memcpy(old, now, sizeof(now));
        memset(now, 0, sizeof(now));

        for(j=0; j<=N; ++j)
            for(k=0; k<=K; ++k)
                for(F=0; F<2; ++F)
                    for(S=0; S<2; ++S)
                    {
                        new_k = k + a[i] * (2 * j + F + S);
                        if(new_k > K) continue;

                        add_to(now[j+1][new_k][F][S], j, old[j][k][F][S]);
                        add_to(now[j][new_k][F][S], 2*j, old[j][k][F][S]);
                        if(j) add_to(now[j-1][new_k][F][S], j, old[j][k][F][S]);

                        if(F)
                        {
                            add_to(now[j+1][new_k][1][S], 1, old[j][k][F][S]);
                            add_to(now[j][new_k][1][S], 1, old[j][k][F][S]);
                            add_to(now[j+1][new_k][0][S], 1, old[j][k][F][S]);
                            add_to(now[j][new_k][0][S], 1, old[j][k][F][S]);
                        }

                        if(S)
                        {
                            add_to(now[j+1][new_k][F][1], 1, old[j][k][F][S]);
                            add_to(now[j][new_k][F][1], 1, old[j][k][F][S]);
                            add_to(now[j+1][new_k][F][0], 1, old[j][k][F][S]);
                            add_to(now[j][new_k][F][0], 1, old[j][k][F][S]);
                        }
                    }
    }

    int ans = 0;
    for(i=0; i<=K; ++i) add_to(ans, 1, now[0][i][0][0]);
    cout << ans << '\n';

    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 248 KB Output is correct
2 Correct 4 ms 3552 KB Output is correct
3 Correct 5 ms 3624 KB Output is correct
4 Correct 6 ms 3700 KB Output is correct
5 Correct 8 ms 3712 KB Output is correct
6 Correct 8 ms 3712 KB Output is correct
7 Correct 6 ms 3712 KB Output is correct
8 Correct 7 ms 3712 KB Output is correct
9 Correct 8 ms 3712 KB Output is correct
10 Correct 6 ms 3748 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 3876 KB Output is correct
2 Correct 8 ms 3876 KB Output is correct
3 Correct 8 ms 3876 KB Output is correct
4 Correct 8 ms 3876 KB Output is correct
5 Correct 8 ms 3876 KB Output is correct
6 Correct 8 ms 3876 KB Output is correct
7 Correct 8 ms 3876 KB Output is correct
8 Correct 9 ms 3876 KB Output is correct
9 Correct 8 ms 3876 KB Output is correct
10 Correct 8 ms 3876 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 248 KB Output is correct
2 Correct 4 ms 3552 KB Output is correct
3 Correct 5 ms 3624 KB Output is correct
4 Correct 6 ms 3700 KB Output is correct
5 Correct 8 ms 3712 KB Output is correct
6 Correct 8 ms 3712 KB Output is correct
7 Correct 6 ms 3712 KB Output is correct
8 Correct 7 ms 3712 KB Output is correct
9 Correct 8 ms 3712 KB Output is correct
10 Correct 6 ms 3748 KB Output is correct
11 Correct 8 ms 3876 KB Output is correct
12 Correct 8 ms 3876 KB Output is correct
13 Correct 8 ms 3876 KB Output is correct
14 Correct 8 ms 3876 KB Output is correct
15 Correct 8 ms 3876 KB Output is correct
16 Correct 8 ms 3876 KB Output is correct
17 Correct 8 ms 3876 KB Output is correct
18 Correct 9 ms 3876 KB Output is correct
19 Correct 8 ms 3876 KB Output is correct
20 Correct 8 ms 3876 KB Output is correct
21 Correct 15 ms 3876 KB Output is correct
22 Correct 414 ms 3876 KB Output is correct
23 Correct 445 ms 3876 KB Output is correct
24 Correct 454 ms 3952 KB Output is correct
25 Correct 457 ms 4068 KB Output is correct
26 Correct 414 ms 4068 KB Output is correct
27 Correct 165 ms 4068 KB Output is correct
28 Correct 230 ms 4068 KB Output is correct
29 Correct 389 ms 4068 KB Output is correct
30 Correct 468 ms 4068 KB Output is correct