Submission #963095

# Submission time Handle Problem Language Result Execution time Memory
963095 2024-04-14T13:57:51 Z study Skyscraper (JOI16_skyscraper) C++17
0 / 100
687 ms 368416 KB
#include <bits/stdc++.h>
#define int long long
using namespace std;

const int N = 1<<14, inf = LLONG_MAX/2;

int dp[14][101][N];
vector<int> a;

int32_t main(){
        ios::sync_with_stdio(0);
        cin.tie(0);
        int n,L;
        cin >> n >> L;
        a = vector<int>(n+1);
        for (int i=1; i<=n; ++i){
                cin >> a[i];
        }
        fill_n(&dp[0][0][0],14*N*101,0);
        dp[0][0][0] = 1;
        for (int mask=0; mask<(1<<n); ++mask){
                for (int sum=0; sum<=L; ++sum){
                        for (int last=0; last<=n; ++last){
                                if (last != 0 and !(mask&(1<<(last-1)))) continue;
                                for (int unused=1; unused<=n; ++unused){
                                        if (unused == last or !(mask&(1<<(unused-1)))) continue;
                                        int sum2 = sum;
                                        if (last != 0) sum2 += abs(a[unused]-a[last]);
                                        if (sum2 <= L)
                                                dp[unused][sum2][mask] += dp[last][sum][mask-(1<<(unused-1))];
                                }
                        }
                }
        }
        int ans = 0;
        for (int k=0; k<=n; ++k){
                for (int j=0; j<=L; ++j){
                        ans += dp[k][j][(1<<n)-1];
                }
        }
        cout << ans;
        return 0;

}
# Verdict Execution time Memory Grader output
1 Correct 84 ms 181584 KB Output is correct
2 Correct 36 ms 181592 KB Output is correct
3 Correct 38 ms 181596 KB Output is correct
4 Correct 36 ms 181588 KB Output is correct
5 Runtime error 259 ms 368416 KB Execution killed with signal 11
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 141 ms 181584 KB Output is correct
2 Runtime error 687 ms 368152 KB Execution killed with signal 11
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 84 ms 181584 KB Output is correct
2 Correct 36 ms 181592 KB Output is correct
3 Correct 38 ms 181596 KB Output is correct
4 Correct 36 ms 181588 KB Output is correct
5 Runtime error 259 ms 368416 KB Execution killed with signal 11
6 Halted 0 ms 0 KB -