답안 #40162

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
40162 2018-01-28T19:54:15 Z evpipis Skyscraper (JOI16_skyscraper) C++
15 / 100
1 ms 131864 KB
#include <bits/stdc++.h>
using namespace std;

const int len = 105, mod = 1e9+7;
int n, a[len], dp[len][len][1005][3];

int solve(int i, int j, int rem, int l){
    if (j < 0 || rem < 0 || l > 2) return 0;
    //printf("cur_state = %d, %d, %d, %d\n", i, j, rem, l);
    if (i == n+1) return (j == 1 && l == 2);
    if (dp[i][j][rem][l] != -1) return dp[i][j][rem][l];

    int ans = 0, c = a[i+1]-a[i];
    // Case 1: combine 2 ccs
    if (j >= 2){
        int temp = solve(i+1, j-1, rem-c*(2*(j-1)-l), l);
        if (l == 0)
            ans = (ans + j*(j-1)*1LL*temp)%mod;
        else if (l == 1)
            ans = (ans + (j-1)*(j-1)*1LL*temp)%mod;
        else{
            if (i == n) ans = (ans+temp)%mod;
            else ans = (ans + (j-2)*(j-1)*1LL*temp)%mod;
        }
    }

    // Case 2: create +1 cc
    // do not add an endpoint
    ans = (ans+solve(i+1, j+1, rem-c*(2*(j+1)-l), l))%mod;
    // add an  endpoint
    ans = (ans+(2-l)*1LL*solve(i+1, j+1, rem-c*(2*(j+1)-l-1), l+1))%mod;
    //i think its right!

    // just enlarge 1 cc
    if (j){
        // do not add an endpoint
        ans = (ans+(2*j-l)*1LL*solve(i+1, j, rem-c*(2*j-l), l))%mod;
        // add an endpoint
        int temp = solve(i+1, j, rem-c*(2*j-l-1), l+1);
        if (i == n)
            ans = (ans+(2-l)*j*1LL*temp)%mod;
        else
            ans = (ans+(2-l)*(j-l)*1LL*temp)%mod;
    }
    //if this is right...something else is wrong...

    return dp[i][j][rem][l] = ans;
}

int main(){
    int l;
    scanf("%d %d", &n, &l);
    for (int i = 1; i <= n; i++)
        scanf("%d", &a[i]);
    sort(a+1, a+n+1);
    a[n+1] = a[n];

    for (int i = 1; i <= n; i++)
        for (int j = 0; j <= n; j++)
            for (int rem = 0; rem <= l; rem++)
                dp[i][j][rem][0] = dp[i][j][rem][1] = dp[i][j][rem][2] = -1;

    printf("%d\n", solve(1, 0, l, 0));
    return 0;
}

Compilation message

skyscraper.cpp: In function 'int main()':
skyscraper.cpp:52:27: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d %d", &n, &l);
                           ^
skyscraper.cpp:54:27: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d", &a[i]);
                           ^
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 131864 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 131864 KB Output is correct
2 Correct 0 ms 131864 KB Output is correct
3 Correct 1 ms 131864 KB Output is correct
4 Correct 1 ms 131864 KB Output is correct
5 Correct 1 ms 131864 KB Output is correct
6 Correct 0 ms 131864 KB Output is correct
7 Correct 1 ms 131864 KB Output is correct
8 Correct 1 ms 131864 KB Output is correct
9 Correct 1 ms 131864 KB Output is correct
10 Correct 1 ms 131864 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 131864 KB Output isn't correct
2 Halted 0 ms 0 KB -