Submission #365428

# Submission time Handle Problem Language Result Execution time Memory
365428 2021-02-11T16:26:56 Z BartolM Skyscraper (JOI16_skyscraper) C++17
20 / 100
938 ms 94700 KB
#include <bits/stdc++.h>

using namespace std;

#define X first
#define Y second
#define mp make_pair
#define pb push_back
typedef long long ll;
typedef pair <int, int> pii;
typedef pair <int, pii> pip;
typedef pair <pii, int> ppi;
typedef pair <ll, ll> pll;

const int INF=0x3f3f3f3f;
const int N=14;
const int MOD=1e9+7;

int n, m;
int p[N];
int dp[(1<<14)+2][N][105];

int add(int a, int b) {
    return (a+b)%MOD;
}

int rek(int mask, int pr, int br) {
    if (br>m) return 0;
    if (__builtin_popcount(mask)==n) return 1;

    int &ret=dp[mask][pr][br];
    if (ret!=-1) return ret;

    ret=0;
    for (int i=0; i<n; ++i) {
        if (mask & (1<<i)) continue;
        ret=add(ret, rek(mask | (1<<i), i, br+abs(p[i]-p[pr])));
    }
    return ret;
}

void solve() {
    sort(p, p+n);
    int sol=0;
    do {
        int res=0;
        for (int i=1; i<n; ++i) res+=abs(p[i]-p[i-1]);
        sol+=res<=m;
    }
    while (next_permutation(p, p+n));
    printf("%d\n", sol);
}

void load() {
    scanf("%d %d", &n, &m);
    for (int i=0; i<n; ++i) scanf("%d", &p[i]);
}

int main() {
    load();
    assert(n<=14);

    if (n<=8) {
        solve();
        return 0;
    }

    memset(dp, -1, sizeof dp);
    int sol=0;
    for (int i=0; i<n; ++i) sol=add(sol, rek((1<<i), i, 0));
    printf("%d\n", sol);
    return 0;
}

Compilation message

skyscraper.cpp: In function 'void load()':
skyscraper.cpp:55:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   55 |     scanf("%d %d", &n, &m);
      |     ~~~~~^~~~~~~~~~~~~~~~~
skyscraper.cpp:56:34: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   56 |     for (int i=0; i<n; ++i) scanf("%d", &p[i]);
      |                             ~~~~~^~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 123 ms 94572 KB Output is correct
2 Correct 98 ms 94572 KB Output is correct
3 Correct 673 ms 94648 KB Output is correct
4 Correct 93 ms 94572 KB Output is correct
5 Correct 75 ms 94572 KB Output is correct
6 Correct 602 ms 94628 KB Output is correct
7 Correct 83 ms 94572 KB Output is correct
8 Correct 608 ms 94700 KB Output is correct
9 Correct 938 ms 94572 KB Output is correct
10 Correct 101 ms 94700 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 123 ms 94572 KB Output is correct
12 Correct 98 ms 94572 KB Output is correct
13 Correct 673 ms 94648 KB Output is correct
14 Correct 93 ms 94572 KB Output is correct
15 Correct 75 ms 94572 KB Output is correct
16 Correct 602 ms 94628 KB Output is correct
17 Correct 83 ms 94572 KB Output is correct
18 Correct 608 ms 94700 KB Output is correct
19 Correct 938 ms 94572 KB Output is correct
20 Correct 101 ms 94700 KB Output is correct
21 Incorrect 50 ms 94572 KB Output isn't correct
22 Halted 0 ms 0 KB -