답안 #681600

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
681600 2023-01-13T12:34:22 Z vjudge1 Skyscraper (JOI16_skyscraper) C++14
20 / 100
2000 ms 1460 KB
#include <iostream>
#include <algorithm>
using namespace std;
const int N = 100 +2;
const int M = 1000 +2;
const int mod = 1e9+7;
typedef pair<int,int> pii;

inline int add(int x, int y)
{
    return (x+y>=mod ? x+y-mod : x+y);
}

inline int gun(int x, int y)
{
    return ((x*1ll*y)%mod);
}

int n,l;
int a[N];
int dp[N][M][M][3];
bool vis[N][M][M][3];

int solve(int idx, int comps, int sum, int matha)
{
    if(sum > l)
        return 0;
    if(comps < 0 || comps >n)
        return 0;
    if(comps == 0 && idx>0)
        return 0;
    if(matha > 2)
        return 0;
    if(idx==n)
    {
        if(comps == 1 && matha == 2)
            return 1;
        return 0;
    }
    int &ret = dp[idx][comps][sum][matha];
    if(vis[idx][comps][sum][matha])
        return ret;
    int prv = (idx-1>=0?a[idx-1] : 0);
    int notun = sum + (a[idx]-prv)*(2*comps - matha);
    int ans = 0;
    //Create
    ans = add(ans, gun(comps+1 - matha, solve(idx+1, comps+1, notun, matha)));
    //merge
    if(comps >= 2)
        ans = add(ans, gun(comps-1, solve(idx+1, comps-1, notun, matha)) );
    //add
    if(comps>=1)
        ans = add(ans, gun(2*comps-matha, solve(idx+1, comps, notun, matha)));
    //notun matha
    ans = add(ans, gun(2-matha, solve(idx+1, comps+1, notun, matha+1)));
    //mathay lagao
    ans = add(ans, gun(2-matha, solve(idx+1, comps, notun, matha+1)));
    return ret = ans;
}
int32_t main()
{
    scanf("%d %d",&n,&l);
    for(int i=0; i<n; i++)
    {
        scanf("%d",&a[i]);
    }
    sort(a,a+n);
    if(n==1)
    {
        cout<<"1\n";
        return 0;
    }
    printf("%d\n",solve(0,0,0,0));
    return 0;
}

Compilation message

skyscraper.cpp: In function 'int32_t main()':
skyscraper.cpp:62:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   62 |     scanf("%d %d",&n,&l);
      |     ~~~~~^~~~~~~~~~~~~~~
skyscraper.cpp:65:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   65 |         scanf("%d",&a[i]);
      |         ~~~~~^~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 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 468 KB Output is correct
8 Correct 1 ms 468 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 Correct 53 ms 752 KB Output is correct
2 Correct 4 ms 596 KB Output is correct
3 Correct 75 ms 664 KB Output is correct
4 Correct 3 ms 596 KB Output is correct
5 Correct 3 ms 596 KB Output is correct
6 Correct 22 ms 708 KB Output is correct
7 Correct 2 ms 596 KB Output is correct
8 Correct 69 ms 696 KB Output is correct
9 Correct 182 ms 716 KB Output is correct
10 Correct 7 ms 628 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 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 468 KB Output is correct
8 Correct 1 ms 468 KB Output is correct
9 Correct 1 ms 468 KB Output is correct
10 Correct 1 ms 468 KB Output is correct
11 Correct 53 ms 752 KB Output is correct
12 Correct 4 ms 596 KB Output is correct
13 Correct 75 ms 664 KB Output is correct
14 Correct 3 ms 596 KB Output is correct
15 Correct 3 ms 596 KB Output is correct
16 Correct 22 ms 708 KB Output is correct
17 Correct 2 ms 596 KB Output is correct
18 Correct 69 ms 696 KB Output is correct
19 Correct 182 ms 716 KB Output is correct
20 Correct 7 ms 628 KB Output is correct
21 Execution timed out 2070 ms 1460 KB Time limit exceeded
22 Halted 0 ms 0 KB -