QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#327604#8228. 排序NATURAL6100 ✓1666ms12140kbC++141.6kb2024-02-15 11:17:122024-02-15 11:17:14

Judging History

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

  • [2024-02-15 11:17:14]
  • 评测
  • 测评结果:100
  • 用时:1666ms
  • 内存:12140kb
  • [2024-02-15 11:17:12]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
#define mod 1000000007
inline int qread()
{
    int a=0,f=1;char ch=getchar();
    while(!isdigit(ch)){if(ch=='-')f=-1;ch=getchar();}
    while(isdigit(ch)){(a*=10)+=(ch^48);ch=getchar();}
    return a*f;
}
int n,m,d[20],mp[20][20],pos[20][40],cnt[20],cl[20],S,s,del,siz[20];
pair<int,int>dp[2000010];
inline int get_pos(int id,int rk,int sz){return mp[id][rk]&((1<<min(30,sz*d[id]))-1);}
int main()
{
    n=qread(),m=qread();
    for(int i=1;i<=m;++i)
    {
        d[i]=qread();
        for(int j=0;j<n;++j)mp[i][j%d[i]]|=(1<<j);
    }
    for(int i=0;i<n;++i)pos[i%d[1]][cnt[i%d[1]]++]=i;
    cl[0]=dp[0].first=1;
    for(int i=0;i<d[1];++i)cl[i+1]=cl[i]*(cnt[i]+1),dp[0].second+=cnt[i]*(cnt[i]-1)>>1;
    for(int i=0;i<=cl[d[1]]-2;++i)
    {
        S=0;
        for(int j=0;j<d[1];++j)S|=get_pos(1,j,siz[j]=i/cl[j]%(cnt[j]+1));
        for(int j=0,p;j<d[1];++j)if(cnt[j]^siz[j])
        {
            del=0,s=S;p=pos[j][siz[j]];
            for(int k=2,tp,rk;k<=m;++k)
            {
                tp=s;s=0;rk=p%d[k];
                del+=__builtin_popcount((tp&mp[k][rk])>>p);
                p=rk+__builtin_popcount(tp&mp[k][rk])*d[k];
                for(int l=0;l<d[k];++l)s|=get_pos(k,l,__builtin_popcount(tp&mp[k][l]));
            }
            if(dp[i].second+del>dp[i+cl[j]].second)dp[i+cl[j]]=make_pair(dp[i].first,dp[i].second+del);
            else if(dp[i].second+del==dp[i+cl[j]].second)(dp[i+cl[j]].first+=dp[i].first)%=mod;
        }
    }
    printf("%d %d\n",dp[cl[d[1]]-1].second,dp[cl[d[1]]-1].first);
    return 0;
}

詳細信息

Subtask #1:

score: 18
Accepted

Test #1:

score: 18
Accepted
time: 1ms
memory: 3988kb

input:

2 2
2 1

output:

1 1

result:

ok 2 number(s): "1 1"

Test #2:

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

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: 3716kb

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: 3788kb

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: 3768kb

input:

8 3
8 7 1

output:

22 7

result:

ok 2 number(s): "22 7"

Test #6:

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

input:

8 1
1

output:

28 1

result:

ok 2 number(s): "28 1"

Subtask #2:

score: 27
Accepted

Dependency #1:

100%
Accepted

Test #7:

score: 27
Accepted
time: 0ms
memory: 3732kb

input:

16 2
6 1

output:

77 15

result:

ok 2 number(s): "77 15"

Test #8:

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

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: 16ms
memory: 3812kb

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: 11ms
memory: 3804kb

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: 2ms
memory: 3820kb

input:

16 4
7 6 2 1

output:

52 9

result:

ok 2 number(s): "52 9"

Subtask #3:

score: 21
Accepted

Dependency #2:

100%
Accepted

Test #12:

score: 21
Accepted
time: 1ms
memory: 3704kb

input:

22 3
5 3 1

output:

100 1

result:

ok 2 number(s): "100 1"

Test #13:

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

input:

22 1
1

output:

231 1

result:

ok 2 number(s): "231 1"

Test #14:

score: 0
Accepted
time: 52ms
memory: 4544kb

input:

22 4
10 8 3 1

output:

97 4

result:

ok 2 number(s): "97 4"

Test #15:

score: 0
Accepted
time: 69ms
memory: 4612kb

input:

22 5
10 7 6 3 1

output:

92 70

result:

ok 2 number(s): "92 70"

Test #16:

score: 0
Accepted
time: 92ms
memory: 4808kb

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: 153ms
memory: 4532kb

input:

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

output:

109 1

result:

ok 2 number(s): "109 1"

Subtask #4:

score: 10
Accepted

Test #18:

score: 10
Accepted
time: 2ms
memory: 3812kb

input:

14 2
10 1

output:

61 210

result:

ok 2 number(s): "61 210"

Test #19:

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

input:

18 2
2 1

output:

117 1

result:

ok 2 number(s): "117 1"

Test #20:

score: 0
Accepted
time: 78ms
memory: 7788kb

input:

30 2
9 1

output:

264 84

result:

ok 2 number(s): "264 84"

Test #21:

score: 0
Accepted
time: 67ms
memory: 6968kb

input:

29 2
9 1

output:

253 36

result:

ok 2 number(s): "253 36"

Test #22:

score: 0
Accepted
time: 12ms
memory: 4312kb

input:

25 2
8 1

output:

195 8

result:

ok 2 number(s): "195 8"

Subtask #5:

score: 24
Accepted

Dependency #1:

100%
Accepted

Dependency #2:

100%
Accepted

Dependency #3:

100%
Accepted

Dependency #4:

100%
Accepted

Test #23:

score: 24
Accepted
time: 608ms
memory: 11956kb

input:

30 4
10 9 5 1

output:

188 40

result:

ok 2 number(s): "188 40"

Test #24:

score: 0
Accepted
time: 1574ms
memory: 11864kb

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: 1314ms
memory: 11904kb

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: 1300ms
memory: 11904kb

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: 898ms
memory: 12140kb

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: 1666ms
memory: 11984kb

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: 713ms
memory: 9856kb

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