답안 #528166

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
528166 2022-02-19T14:45:15 Z hoainiem Skyscraper (JOI16_skyscraper) C++14
100 / 100
58 ms 16048 KB
#include <bits/stdc++.h>
const int mod = 1e9+7;
double begintime, endtime;

using namespace std;
inline void CALC_TIME()
{    
    endtime = clock();
    cout<<"\nexecution time : "<<(endtime-begintime+1)/1000<<" s";
}
void add(int &x, int y)
{
    x += y;
    if(x >= mod)x -= mod;
}
int n, l, nect, ans = 0, tmp, a[108], f[108][108][1008][3];
int dq(int i, int j, int k, int x)
{
    if(k < 0 || k > l)return 0;
    if(f[i][j][k][x] != -1)return f[i][j][k][x];
    if(i == n)
    {
        if(j == 1 && k == l && x == 2)return f[i][j][k][x] = 1;
        return f[i][j][k][x] = 0;
    }
    int res = 0, tmp = a[i+2]-a[i+1];
    add(res, 1LL*dq(i+1, j+1, k+tmp*(j*2+2-x), x)*(j+1-x)%mod);
    if(x < 2)
        add(res, 1LL*dq(i+1, j+1, k+tmp*(j*2+1-x), x+1)*(2-x)%mod);
    add(res, 1LL*dq(i+1, j, k+tmp*(j*2-x), x)*(j*2-x)%mod);
    if(j != x)
    {
        if(j > 0)
            add(res, 1LL*dq(i+1, j-1, k+tmp*(j*2-2-x), x)*(j-1)%mod);
        if(x < 2)
            add(res, 1LL*dq(i+1, j+1, k+tmp*(j*2+1-x), x+1)*(2-x)%mod);
    }
    return f[i][j][k][x] = res;
}
int main()
{
    begintime = clock();
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cin>>n>>l;
    for(int i = 1; i <= n; i++)
        cin>>a[i];
    if(n == 1)
    {
        cout<<1;
        return 0;
    }
    sort(a+1, a+n+1);
    a[0] = a[1];
    a[n+1] = a[n];
    f[0][0][0][0] = 1;
    for(int i = 0; i <= n; i++)
        for(int j = 0; j <= n; j++)
            for(int k = 0; k <= l; k++)
                for(int o = 0; o <= 2; o++)
                    if(f[i][j][k][o])
                    {
                        tmp = f[i][j][k][o];
                        nect = k+(j*2-o)*(a[i+1]-a[i]);
                        if(nect > l)continue;
                        add(f[i+1][j+1][nect][o], 1LL*tmp*(j+1-o)%mod);
                        if(o < 2)
                            add(f[i+1][j+1][nect][o+1], 1LL*tmp*(2-o)%mod);
                        if(j > 0)
                            add(f[i+1][j][nect][o], 1LL*tmp*(2*j-o)%mod);
                        if(j != o || i+1 == n)
                        {
                            if(j > 1)
                                add(f[i+1][j-1][nect][o], 1LL*tmp*(j-1)%mod);
                            if(o < 2 && j > 0)
                                add(f[i+1][j][nect][o+1], 1LL*tmp*(2-o)%mod);
                        }
                    }
    for(int i = 0; i <= l; i++)
        add(ans, f[n][1][i][2]);
    cout<<ans;
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 332 KB Output is correct
3 Correct 0 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 400 KB Output is correct
6 Correct 1 ms 460 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 460 KB Output is correct
9 Correct 1 ms 460 KB Output is correct
10 Correct 1 ms 460 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 588 KB Output is correct
2 Correct 1 ms 588 KB Output is correct
3 Correct 1 ms 588 KB Output is correct
4 Correct 1 ms 588 KB Output is correct
5 Correct 1 ms 588 KB Output is correct
6 Correct 1 ms 588 KB Output is correct
7 Correct 1 ms 528 KB Output is correct
8 Correct 1 ms 588 KB Output is correct
9 Correct 1 ms 716 KB Output is correct
10 Correct 1 ms 588 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 332 KB Output is correct
3 Correct 0 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 400 KB Output is correct
6 Correct 1 ms 460 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 460 KB Output is correct
9 Correct 1 ms 460 KB Output is correct
10 Correct 1 ms 460 KB Output is correct
11 Correct 1 ms 588 KB Output is correct
12 Correct 1 ms 588 KB Output is correct
13 Correct 1 ms 588 KB Output is correct
14 Correct 1 ms 588 KB Output is correct
15 Correct 1 ms 588 KB Output is correct
16 Correct 1 ms 588 KB Output is correct
17 Correct 1 ms 528 KB Output is correct
18 Correct 1 ms 588 KB Output is correct
19 Correct 1 ms 716 KB Output is correct
20 Correct 1 ms 588 KB Output is correct
21 Correct 2 ms 1228 KB Output is correct
22 Correct 58 ms 16048 KB Output is correct
23 Correct 45 ms 6260 KB Output is correct
24 Correct 48 ms 9224 KB Output is correct
25 Correct 47 ms 6936 KB Output is correct
26 Correct 43 ms 6688 KB Output is correct
27 Correct 23 ms 8140 KB Output is correct
28 Correct 34 ms 9680 KB Output is correct
29 Correct 57 ms 12428 KB Output is correct
30 Correct 47 ms 7056 KB Output is correct