QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#370015#8285. Shell SortSolitaryDreamAC ✓4133ms183836kbC++172.2kb2024-03-28 21:05:222024-03-28 21:05:53

Judging History

你现在查看的是最新测评结果

  • [2024-03-28 21:05:53]
  • 评测
  • 测评结果:AC
  • 用时:4133ms
  • 内存:183836kb
  • [2024-03-28 21:05:22]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;

#define int long long

using pii=pair<int,int>;

const int N=31,P=1e9+7;

map<vector<int>,pii> f;

pii merge(const pii &a,const pii &b)
{
    pii w=a;
    if(b.first>w.first)
        w=b;
    else if(b.first==w.first)
        w.second=(w.second+b.second)%P;
    return w;
}

int pos[N][N],cnt[N];

int bef[N][N],ps[N][N];

int n,m,d[N];

int calc(int S,int p)
{
    int cnt=0;
    for(int i=1;i<=m;i++)
    {
        int nS=0,np=-1;
        for(int j=0;j<d[i];j++)
        {
            
            int all=ps[i][j]&S;
            int all0=ps[i][j]&~S;
            if(j==p%d[i])
            {
                cnt+=__builtin_popcount(all&((1<<p)-1));
                cnt+=__builtin_popcount(all0>>(p+1));
            }
            if(all0)
                nS|=ps[i][j]^bef[i][j+__builtin_popcount(all0)*d[i]-d[i]];
            else
                nS|=ps[i][j];
            if(j==p%d[i])
                np=__builtin_popcount(all0)*d[i]+j-d[i];
        }
        S=nS,p=np;
    }
    return cnt;
}

pii dp(vector<int> s)
{
    if(f.count(s))
        return f[s];
    pii &ret=f[s];
    ret.first=-1e9;
    int hav=0;
    for(int i=0;i<d[1];i++)
        if(s[i])
            hav|=bef[1][pos[i][s[i]-1]];
    bool flag=0;
    for(int i=0;i<d[1];i++)
    {
        if(s[i]==cnt[i])
            continue;
        flag=1;
        s[i]++;
        pii w=dp(s);
        s[i]--;
        int x=pos[i][s[i]];
        w.first+=calc(hav,x);
        ret=merge(ret,w);
    }
    if(!flag)
        ret.first=0,ret.second=1;
    return ret;
}

signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin>>n>>m;
    for(int i=1;i<=m;i++)
        cin>>d[i];
    while(d[1]>n)
    {
        m--;
        for(int i=m;i>=1;i--)
            d[i]=d[i+1];
    }
    for(int i=0;i<d[1];i++)
        for(int j=i;j<n;j+=d[1])
            pos[i][cnt[i]++]=j;
    for(int i=1;i<=m;i++)
        for(int j=0;j<n;j++)
        {
            bef[i][j]=(1<<j);
            ps[i][j%d[i]]|=(1<<j);
            if(j>=d[i])
                bef[i][j]|=bef[i][j-d[i]];
        }
    vector<int> b(d[1]);
    auto [u,v]=dp(b);
    cout<<u/2<<" "<<v<<"\n";
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 3620kb

input:

2 2
2 1

output:

1 1

result:

ok 2 number(s): "1 1"

Test #2:

score: 0
Accepted
time: 1ms
memory: 3868kb

input:

5 4
5 4 2 1

output:

6 4

result:

ok 2 number(s): "6 4"

Test #3:

score: 0
Accepted
time: 1ms
memory: 3540kb

input:

8 4
6 3 2 1

output:

15 4

result:

ok 2 number(s): "15 4"

Test #4:

score: 0
Accepted
time: 1ms
memory: 3612kb

input:

8 6
8 7 5 4 2 1

output:

14 2

result:

ok 2 number(s): "14 2"

Test #5:

score: 0
Accepted
time: 1ms
memory: 3608kb

input:

8 3
8 7 1

output:

22 7

result:

ok 2 number(s): "22 7"

Test #6:

score: 0
Accepted
time: 1ms
memory: 3844kb

input:

8 1
1

output:

28 1

result:

ok 2 number(s): "28 1"

Test #7:

score: 0
Accepted
time: 4ms
memory: 3848kb

input:

16 2
6 1

output:

77 15

result:

ok 2 number(s): "77 15"

Test #8:

score: 0
Accepted
time: 37ms
memory: 5628kb

input:

16 8
10 9 8 7 6 5 4 1

output:

57 5

result:

ok 2 number(s): "57 5"

Test #9:

score: 0
Accepted
time: 38ms
memory: 5616kb

input:

16 10
10 9 8 7 6 5 4 3 2 1

output:

57 3

result:

ok 2 number(s): "57 3"

Test #10:

score: 0
Accepted
time: 40ms
memory: 5624kb

input:

16 7
10 9 8 6 5 4 1

output:

49 1

result:

ok 2 number(s): "49 1"

Test #11:

score: 0
Accepted
time: 8ms
memory: 4060kb

input:

16 4
7 6 2 1

output:

52 9

result:

ok 2 number(s): "52 9"

Test #12:

score: 0
Accepted
time: 6ms
memory: 4176kb

input:

22 3
5 3 1

output:

100 1

result:

ok 2 number(s): "100 1"

Test #13:

score: 0
Accepted
time: 0ms
memory: 3640kb

input:

22 1
1

output:

231 1

result:

ok 2 number(s): "231 1"

Test #14:

score: 0
Accepted
time: 376ms
memory: 21892kb

input:

22 4
10 8 3 1

output:

97 4

result:

ok 2 number(s): "97 4"

Test #15:

score: 0
Accepted
time: 352ms
memory: 21836kb

input:

22 5
10 7 6 3 1

output:

92 70

result:

ok 2 number(s): "92 70"

Test #16:

score: 0
Accepted
time: 375ms
memory: 21704kb

input:

22 6
10 9 8 7 3 1

output:

97 1

result:

ok 2 number(s): "97 1"

Test #17:

score: 0
Accepted
time: 424ms
memory: 21852kb

input:

22 10
10 9 8 7 6 5 4 3 2 1

output:

109 1

result:

ok 2 number(s): "109 1"

Test #18:

score: 0
Accepted
time: 13ms
memory: 4448kb

input:

14 2
10 1

output:

61 210

result:

ok 2 number(s): "61 210"

Test #19:

score: 0
Accepted
time: 0ms
memory: 3860kb

input:

18 2
2 1

output:

117 1

result:

ok 2 number(s): "117 1"

Test #20:

score: 0
Accepted
time: 1319ms
memory: 83664kb

input:

30 2
9 1

output:

264 84

result:

ok 2 number(s): "264 84"

Test #21:

score: 0
Accepted
time: 1032ms
memory: 67864kb

input:

29 2
9 1

output:

253 36

result:

ok 2 number(s): "253 36"

Test #22:

score: 0
Accepted
time: 164ms
memory: 16324kb

input:

25 2
8 1

output:

195 8

result:

ok 2 number(s): "195 8"

Test #23:

score: 0
Accepted
time: 3589ms
memory: 183804kb

input:

30 4
10 9 5 1

output:

188 40

result:

ok 2 number(s): "188 40"

Test #24:

score: 0
Accepted
time: 4090ms
memory: 183836kb

input:

30 9
10 9 8 7 6 5 4 3 1

output:

184 6

result:

ok 2 number(s): "184 6"

Test #25:

score: 0
Accepted
time: 4044ms
memory: 183784kb

input:

30 8
10 9 8 7 4 3 2 1

output:

154 1

result:

ok 2 number(s): "154 1"

Test #26:

score: 0
Accepted
time: 4017ms
memory: 183796kb

input:

30 8
10 8 7 6 5 4 3 1

output:

155 1

result:

ok 2 number(s): "155 1"

Test #27:

score: 0
Accepted
time: 3741ms
memory: 183744kb

input:

30 6
10 8 6 4 3 1

output:

150 4

result:

ok 2 number(s): "150 4"

Test #28:

score: 0
Accepted
time: 4133ms
memory: 183820kb

input:

30 10
10 9 8 7 6 5 4 3 2 1

output:

184 6

result:

ok 2 number(s): "184 6"

Test #29:

score: 0
Accepted
time: 2881ms
memory: 138784kb

input:

29 6
10 9 7 5 3 1

output:

129 200

result:

ok 2 number(s): "129 200"

Extra Test:

score: 0
Extra Test Passed