QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#782173#198. Wsnpmrnhlol100 ✓233ms57272kbC++172.6kb2024-11-25 19:11:262024-11-25 19:11:27

Judging History

This is the latest submission verdict.

  • [2024-11-25 19:11:27]
  • Judged
  • Verdict: 100
  • Time: 233ms
  • Memory: 57272kb
  • [2024-11-25 19:11:26]
  • Submitted

answer

#include <bits/stdc++.h>
using namespace std;
const int N = 3e5;
const int mod = 1e9 + 7;
const int NR = N;
int fact[NR  + 1],inv[NR + 1];
int p(int a,int b){
    int r = 1;
    while(b){
        if(b%2)r = 1ll*r*a%mod;
        a = 1ll*a*a%mod;
        b/=2;
    }
    return r;
}
void precalc(){
    fact[0] = 1;
    for(int i = 1;i <= NR;i++){
        fact[i] = 1ll*fact[i - 1]*i%mod;
    }
    inv[NR] = p(fact[NR],mod - 2);
    for(int i = NR - 1;i >= 0;i--){
        inv[i] = 1ll*inv[i + 1]*(i + 1)%mod;
    }
}
int comb(int n,int k){
    if(n < k || k < 0)return 0;
    return 1ll*fact[n]*inv[k]%mod*inv[n-k]%mod;
}
int n;
int v[N];
vector <int> v2;
int countm(){
    /// down up down up
    auto check = [&](int x) -> bool{
        if((x&2)){
            if(!(x&1) || !(x&4))return 0;
        }
        if((x&8)){
            if(!(x&4) || !(x&16))return 0;
        }
        return 1;
    };
    int m = v2.size();
    vector <vector<int>> dp(m + 1, vector<int>(32, 0));
    dp[m][0] = 1;
    for(int i = m - 1;i >= 0;i--){
        for(int j = 0;j < 32;j++){
            if(!check(j))continue;
            for(int k = j;k < 32;k = ((k + 1)|j)){
                if(!check(k))continue;
                if((k&2)){
                    if(!(j&1) || !(j&4))continue;
                }
                if((k&8)){
                    if(!(j&4) || !(j&16))continue;
                }

                int possib = v2[i];/// blocks
                int options = 0;/// separators
                ///places to put stuff in
                possib-=__builtin_popcount(k^j);
                options+=__builtin_popcount(k^j);
                if(!(k&2) && (j&1))options++;
                if(!(k&2) && (j&4))options++;
                if(!(k&8) && (j&4))options++;
                if(!(k&8) && (j&16))options++;
                //if(comb(possib + options - 1, options - 1) == 0)continue;
                dp[i][k] = (dp[i][k] + 1ll*dp[i + 1][j]*comb(possib + options - 1, options - 1)%mod)%mod;
                //cout<<i<<' '<<j<<' '<<k<<' '<<possib<<' '<<options<<' '<<comb(possib + options - 1, options - 1)<<'\n';
            }
        }
    }
    return dp[0][31];
}
int main(){
    precalc();
    cin>>n;
    for(int i = 0;i < n;i++){
        cin>>v[i];
    }
    sort(v, v + n);
    for(int i = 0;i < n;i++){
        int j = i;
        int cnt = 0;
        while(j < n && v[j] == v[i]){
            cnt++;j++;
        }
        v2.push_back(cnt);
        i = j - 1;
    }
    int x = countm();
    cout<<x<<'\n';
    return 0;
}
/// w shaped means entire array is w shape not a part? why?

Details

Tip: Click on the bar to expand more detailed information

Pretests


Final Tests

Test #1:

score: 5
Accepted
time: 4ms
memory: 5888kb

input:

8
6 3 5 6 8 3 5 7

output:

682

result:

ok single line: '682'

Test #2:

score: 5
Accepted
time: 4ms
memory: 6996kb

input:

13
5 10 20 14 6 14 13 17 20 19 13 13 7

output:

772122

result:

ok single line: '772122'

Test #3:

score: 5
Accepted
time: 4ms
memory: 6460kb

input:

30
94 94 94 94 94 94 94 94 55 55 94 94 94 55 55 94 94 94 55 55 94 94 94 94 55 94 94 55 94 94

output:

1470

result:

ok single line: '1470'

Test #4:

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

input:

50
519 57 173 248 182 393 837 490 374 292 266 542 499 255 570 177 984 975 754 211 326 828 205 86 363 364 386 259 446 156 148 96 972 181 841 365 284 253 611 772 150 535 160 6 730 969 600 200 516 491

output:

503419747

result:

ok single line: '503419747'

Test #5:

score: 5
Accepted
time: 4ms
memory: 6256kb

input:

100
999585 999250 999333 999152 999207 999207 999207 999326 999577 999878 999028 999023 999414 999157 999782 999557 999099 999472 999957 999207 999496 999200 999037 999700 999895 999785 999084 999969 999175 999505 999381 999168 999627 999207 999403 999240 999785 999111 999971 999156 999130 999931 99...

output:

171163369

result:

ok single line: '171163369'

Test #6:

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

input:

200
5175 5816 5175 5816 5175 5816 5816 5175 5816 5175 5175 5175 5175 5816 5816 5175 5175 5816 5175 5175 5175 5816 5175 5816 5816 5816 5175 5175 5816 5175 5816 5816 5175 5816 5175 5175 5175 5816 5816 5816 5816 5175 5175 5816 5175 5816 5175 5175 5175 5816 5175 5175 5175 5175 5816 5175 5175 5816 5175 5...

output:

366639

result:

ok single line: '366639'

Test #7:

score: 5
Accepted
time: 4ms
memory: 6844kb

input:

500
112 720 767 720 153 598 561 720 202 265 491 258 532 720 780 579 772 179 977 720 380 150 258 720 35 720 39 720 112 674 488 868 720 161 475 876 911 265 961 251 797 720 720 720 478 388 404 471 286 720 541 789 248 194 711 720 933 720 720 433 720 800 248 720 720 521 438 720 104 720 712 582 806 325 99...

output:

94107552

result:

ok single line: '94107552'

Test #8:

score: 5
Accepted
time: 4ms
memory: 7196kb

input:

1000
18020 16780 15887 13325 16929 15726 16130 10167 16112 15612 16007 19932 15104 15665 10459 19470 11481 16376 16778 13573 11086 17987 15951 19152 19256 14307 14099 13814 10359 16727 17986 12672 12804 13154 11365 18302 12905 14934 12878 15715 17123 10022 10342 12849 14473 10243 12204 17089 17952 1...

output:

492042730

result:

ok single line: '492042730'

Test #9:

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

input:

2000
765163 765163 765163 765163 765163 235716 765163 765163 765163 281165 765163 281165 281165 281165 765163 281165 281165 765163 281165 765163 281165 765163 765163 765163 281165 281165 281165 235716 765163 765163 281165 235716 765163 281165 765163 765163 765163 765163 765163 765163 235716 765163 2...

output:

363209364

result:

ok single line: '363209364'

Test #10:

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

input:

5000
3105 1435 4931 3902 1151 1335 1098 1854 2657 1662 2714 4908 2816 3587 4336 261 2656 4015 4650 3486 2336 3387 1490 4091 4479 1432 4467 2956 1974 3172 886 2381 3378 4152 4497 2551 514 61 4690 2639 306 2634 2101 770 4915 2824 1189 430 2414 305 4873 851 2141 4112 1826 4559 1553 4525 3801 4550 3977 ...

output:

581786964

result:

ok single line: '581786964'

Test #11:

score: 5
Accepted
time: 9ms
memory: 7280kb

input:

10000
141193 128900 198991 161873 198876 114240 108423 125932 127260 147431 172988 111716 136843 183602 142689 132259 119622 196500 130091 142689 197214 175689 197826 106161 135569 194642 140163 152929 163223 130589 141972 111752 142689 143323 101297 123912 166215 127819 188602 129311 184203 176649 ...

output:

367380640

result:

ok single line: '367380640'

Test #12:

score: 5
Accepted
time: 28ms
memory: 11208kb

input:

30000
354060 924337 555829 91689 733521 137825 382435 958538 683161 290951 744975 174458 151043 534937 237034 794445 482379 629210 962405 337796 581609 110811 109279 198581 179017 36335 30828 689921 969687 326477 701307 587578 195022 259497 846681 19536 702287 40434 509411 161859 597447 432906 47305...

output:

866281129

result:

ok single line: '866281129'

Test #13:

score: 5
Accepted
time: 14ms
memory: 6064kb

input:

50000
491865 491865 754933 754933 491865 491865 491865 754933 754933 491865 491865 491865 754933 491865 491865 754933 754933 491865 491865 491865 754933 491865 754933 491865 754933 491865 754933 491865 491865 491865 491865 754933 754933 491865 754933 491865 754933 491865 491865 754933 754933 491865 ...

output:

900018013

result:

ok single line: '900018013'

Test #14:

score: 5
Accepted
time: 77ms
memory: 22856kb

input:

100000
156692 115463 344496 65180 207025 904449 698318 658072 647270 61729 599969 915987 869287 487198 62418 731879 76449 425182 983957 601643 46232 972992 321059 243836 225904 374283 734144 945816 473547 789120 362072 623498 898704 865015 573835 76612 964064 630023 523429 780586 434231 675167 27836...

output:

637327440

result:

ok single line: '637327440'

Test #15:

score: 5
Accepted
time: 22ms
memory: 6452kb

input:

100000
34192 637466 645795 343113 90759 261291 343113 641172 890214 243778 841281 230332 201780 201780 437758 400102 90759 399139 291881 176972 980545 90759 368908 867045 435773 867045 890214 735167 457079 339483 440607 973445 958894 945766 646225 843338 779369 75959 852684 291881 291881 691839 7086...

output:

764281969

result:

ok single line: '764281969'

Test #16:

score: 5
Accepted
time: 155ms
memory: 39956kb

input:

200000
531668 579294 936652 502245 868742 706981 588829 882533 989425 993223 791046 582847 692192 574648 858267 906976 814695 961041 607611 730721 602717 553035 951028 528811 889972 606243 552333 516641 875813 776173 846497 880510 947204 880238 710490 738887 630903 889543 800463 692104 929101 948343...

output:

428631096

result:

ok single line: '428631096'

Test #17:

score: 5
Accepted
time: 40ms
memory: 7212kb

input:

200000
2089 1721 770 1853 2100 759 2997 3564 3440 211 1577 1741 2331 3761 3322 3180 2936 3436 210 1766 1813 2458 1256 700 983 2816 1741 1493 2686 112 26 2975 1389 2595 689 2879 3976 1147 3836 762 2213 3071 1742 234 1934 2019 1903 2032 814 1287 2209 3244 577 3084 319 1533 3938 1032 2164 2331 1429 909...

output:

506457150

result:

ok single line: '506457150'

Test #18:

score: 5
Accepted
time: 39ms
memory: 7152kb

input:

300000
97 95 95 95 95 95 95 95 95 95 97 95 95 95 97 97 95 95 97 95 95 97 95 95 95 95 95 95 95 97 95 97 95 95 97 97 95 95 97 95 97 97 97 95 97 95 95 97 95 97 95 97 97 95 95 95 97 95 95 95 95 95 97 95 95 95 95 95 95 95 95 97 95 95 97 95 95 97 97 95 97 95 97 95 95 95 95 95 95 95 97 95 95 95 95 95 97 97...

output:

391288279

result:

ok single line: '391288279'

Test #19:

score: 5
Accepted
time: 233ms
memory: 57272kb

input:

300000
352089 342054 315338 74643 33360 530343 893537 73233 482513 115907 293978 735776 168290 267256 783713 12612 649551 571393 381304 364972 882828 13639 335116 837201 267205 307983 311663 564990 653841 484981 845932 573996 239873 722527 651604 143206 531449 890625 311064 264028 426996 626045 4054...

output:

399390399

result:

ok single line: '399390399'

Test #20:

score: 5
Accepted
time: 223ms
memory: 55260kb

input:

300000
23876 282555 599510 374942 197909 440286 233509 120010 629442 657458 882076 589456 788090 323132 286484 971337 705531 437949 835650 743469 840253 715759 143267 875552 463863 612498 671487 664850 459103 706010 964862 507250 755787 328152 177103 192758 368767 45166 889566 366239 112631 650851 7...

output:

481673245

result:

ok single line: '481673245'