QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#919571#6143. 滚榜KiharaTouma100 ✓172ms391048kbC++141.9kb2025-02-28 11:22:402025-02-28 11:22:43

Judging History

This is the latest submission verdict.

  • [2025-02-28 11:22:43]
  • Judged
  • Verdict: 100
  • Time: 172ms
  • Memory: 391048kb
  • [2025-02-28 11:22:40]
  • Submitted

answer

//qoj6143
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

ll f[1<<13][14][510];
int n, m, a[15], mx, sum, id;

int main(){
    scanf("%d%d", &n, &m);
    for(int i = 1; i <= n; ++ i){
        scanf("%d", &a[i]);
        if(a[i] > mx){
            mx = a[i];
            id = i;
        }
        sum += a[i];
    }
    for(int i = 1; i <= n; ++ i){
        if(i <= id){
            f[1<<i-1][i][0] = 1;
        } else {
            f[1<<i-1][i][n] = 1;
        }
    }
    m -= mx * n - sum;
    if(m < 0){
        puts("0");
        return 0;
    }
    for(int i = 1; i < (1 << n); ++ i){
        int ppc = n - __builtin_popcount(i);
        for(int j = 1; j <= n; ++ j){
            if(!(i & (1 << j - 1))){
                continue;
            }
            for(int k = 0; k <= m; ++ k){
                if(!f[i][j][k]){
                    continue;
                }
                // printf("%d %d %d %lld\n", i, j, k, f[i][j][k]);
                for(int p = 1; p <= n; ++ p){
                    if(i & (1 << p - 1)){
                        continue;
                    }
                    if(a[p] <= a[j]){
                        if(p < j){
                            f[i|(1<<p-1)][p][k] += f[i][j][k];
                        } else if(k + ppc <= m){
                            f[i|(1<<p-1)][p][k+ppc] += f[i][j][k];
                        }
                    } else {
                        if(k + ppc * (a[p] - a[j]) <= m){
                            f[i|(1<<p-1)][p][k+ppc*(a[p]-a[j])] += f[i][j][k];
                        }
                    }
                }
            }
        }
    }
    ll ans = 0;
    for(int i = 1; i <= n; ++ i){
        for(int j = 0; j <= m; ++ j){
            ans += f[(1<<n)-1][i][j];
        }
    }
    printf("%lld\n", ans);
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Pretests


Final Tests

Test #1:

score: 5
Accepted
time: 1ms
memory: 3840kb

input:

2 8
8950 8954

output:

2

result:

ok 1 number(s): "2"

Test #2:

score: 5
Accepted
time: 0ms
memory: 5968kb

input:

2 10
8841 8843

output:

2

result:

ok 1 number(s): "2"

Test #3:

score: 5
Accepted
time: 0ms
memory: 5972kb

input:

3 9
8765 8761 8765

output:

2

result:

ok 1 number(s): "2"

Test #4:

score: 5
Accepted
time: 0ms
memory: 3968kb

input:

3 8
8385 8385 8387

output:

6

result:

ok 1 number(s): "6"

Test #5:

score: 5
Accepted
time: 0ms
memory: 3840kb

input:

3 9
8581 8585 8582

output:

2

result:

ok 1 number(s): "2"

Test #6:

score: 5
Accepted
time: 0ms
memory: 18148kb

input:

8 100
8856 8864 8858 8860 8856 8863 8859 8857

output:

17589

result:

ok 1 number(s): "17589"

Test #7:

score: 5
Accepted
time: 0ms
memory: 18224kb

input:

8 100
8238 8239 8245 8244 8245 8244 8238 8244

output:

32475

result:

ok 1 number(s): "32475"

Test #8:

score: 5
Accepted
time: 1ms
memory: 18424kb

input:

8 100
9804 9806 9807 9802 9801 9803 9801 9806

output:

37012

result:

ok 1 number(s): "37012"

Test #9:

score: 5
Accepted
time: 3ms
memory: 59552kb

input:

10 200
8002 8014 8011 8013 8002 8003 8002 8016 8009 8004

output:

606309

result:

ok 1 number(s): "606309"

Test #10:

score: 5
Accepted
time: 6ms
memory: 61548kb

input:

10 200
8324 8323 8328 8322 8325 8328 8328 8323 8334 8323

output:

2504995

result:

ok 1 number(s): "2504995"

Test #11:

score: 5
Accepted
time: 5ms
memory: 61344kb

input:

10 200
9416 9415 9417 9404 9408 9409 9410 9416 9415 9411

output:

2553164

result:

ok 1 number(s): "2553164"

Test #12:

score: 5
Accepted
time: 7ms
memory: 61552kb

input:

10 200
9422 9430 9425 9425 9425 9423 9431 9428 9432 9434

output:

2687280

result:

ok 1 number(s): "2687280"

Test #13:

score: 5
Accepted
time: 41ms
memory: 229400kb

input:

12 300
9281 9292 9279 9280 9289 9291 9285 9279 9280 9281 9290 9281

output:

197821618

result:

ok 1 number(s): "197821618"

Test #14:

score: 5
Accepted
time: 49ms
memory: 233160kb

input:

12 300
9737 9726 9731 9736 9723 9727 9722 9732 9736 9733 9737 9728

output:

196607151

result:

ok 1 number(s): "196607151"

Test #15:

score: 5
Accepted
time: 48ms
memory: 231184kb

input:

12 300
8707 8708 8712 8704 8705 8704 8716 8711 8713 8712 8702 8710

output:

337047589

result:

ok 1 number(s): "337047589"

Test #16:

score: 5
Accepted
time: 42ms
memory: 231600kb

input:

12 300
9200 9194 9191 9195 9197 9192 9206 9206 9197 9198 9192 9202

output:

164570332

result:

ok 1 number(s): "164570332"

Test #17:

score: 5
Accepted
time: 172ms
memory: 380288kb

input:

13 500
8217 8233 8238 8217 8237 8237 8217 8217 8230 8234 8225 8223 8220

output:

1500488819

result:

ok 1 number(s): "1500488819"

Test #18:

score: 5
Accepted
time: 168ms
memory: 391048kb

input:

13 500
9781 9780 9772 9779 9785 9788 9788 9777 9791 9784 9782 9777 9768

output:

4627756434

result:

ok 1 number(s): "4627756434"

Test #19:

score: 5
Accepted
time: 158ms
memory: 390320kb

input:

13 500
8096 8078 8103 8104 8085 8089 8081 8085 8102 8095 8097 8100 8090

output:

1388414345

result:

ok 1 number(s): "1388414345"

Test #20:

score: 5
Accepted
time: 165ms
memory: 379288kb

input:

13 500
8739 8728 8743 8727 8730 8735 8733 8738 8731 8743 8728 8722 8722

output:

3106123719

result:

ok 1 number(s): "3106123719"

Extra Test:

score: 0
Extra Test Passed