QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#406146#8228. 排序Eric_cai100 ✓1519ms174720kbC++141.9kb2024-05-06 21:06:212024-05-06 21:06:34

Judging History

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

  • [2024-05-06 21:06:34]
  • 评测
  • 测评结果:100
  • 用时:1519ms
  • 内存:174720kb
  • [2024-05-06 21:06:21]
  • 提交

answer

#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int mod=1e9+7;
vector<int> vec[(int)(3e6+5)];
int zt[int(3e6+5)],sz[105][105],z[105][105],mul[105],d[105],lst[105][105];
int n,m,num,p[1<<15],f[(int)(3e6+5)],g[(int)(3e6+5)];
int lowbit(int x)
{
	return x&(-x);
}
int pct(int x)
{
	return p[x&((1<<15)-1)]+p[x>>15];
}
int ps[105][105][105],suf[105][105];
int main()
{
	int s,add,pos,t[105],x;
	cin>>n>>m;
	for(int i=1;i<=m;i++) cin>>d[i];
	for(int i=1;i<=m;i++)
	{
		for(int j=0;j<n;j++)
		{
			lst[i][j%d[i]]=j,ps[i][j%d[i]][++sz[i][j%d[i]]]=j;
			for(int k=j;k<n;k+=d[i]) suf[i][j]|=(1<<k); 
			for(int k=j%d[i];k<=j;k+=d[i]) z[i][j]|=(1<<k);
		}
	}
	for(int i=1;i<=m;i++)
		for(int j=0;j<d[i];j++) ps[i][j][sz[i][j]+1]=n;
	for(int i=1;i<(1<<15);i++) p[i]=p[i^lowbit(i)]+1;
	mul[0]=1;
	for(int i=1;i<d[1];i++) mul[i]=mul[i-1]*(sz[1][i-1]+1);
	for(int i=0;i<d[1];i++) num+=mul[i]*sz[1][i];
	for(int i=0;i<=num;i++)
	{
		s=i;
		for(int j=0;j<d[1];j++)
		{
			for(int k=0;k<s%(sz[1][j]+1);k++) zt[i]|=(1<<(k*d[1]+j));
			vec[i].push_back(s%(sz[1][j]+1));
			s/=(sz[1][j]+1);
		}
	}
	g[0]=1;
	for(int i=0;i<=num;i++)
	{
	//	cout<<zt[i]<<' '<<f[i]<<' '<<g[i]<<'\n';
		t[0]=zt[i];
		for(int j=1;j<=m;j++)
		{
			t[j]=t[j-1];
			for(int k=0;k<d[j];k++)
			{
				x=t[j]&z[j][lst[j][k]];
				t[j]^=x^suf[j][ps[j][k][sz[j][k]-pct(x)+1]];
			}
		}
		for(int j=0;j<d[1];j++)
		{
			if(vec[i][j]==sz[1][j]) continue;
			add=0,s=zt[i],pos=vec[i][j]*d[1]+j;
			for(int k=1;k<=m;k++)
			{
				add+=pct(s&z[k][pos]);
				//cout<<zt[i]<<' '<<s<<' '<<k<<' '<<pos<<' '<<add<<'\n';
				pos=ps[k][pos%d[k]][sz[k][pos%d[k]]-pct(s&z[k][lst[k][pos%d[k]]])];
				s=t[k];
			}
			if(f[i+mul[j]]<f[i]+add)
			{
				f[i+mul[j]]=f[i]+add;
				g[i+mul[j]]=g[i];
			}
			else if(f[i+mul[j]]==f[i]+add) g[i+mul[j]]=(g[i]+g[i+mul[j]])%mod;
		}
	}
	cout<<f[num]<<' '<<g[num]<<'\n';
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 18
Accepted

Test #1:

score: 18
Accepted
time: 11ms
memory: 78248kb

input:

2 2
2 1

output:

1 1

result:

ok 2 number(s): "1 1"

Test #2:

score: 18
Accepted
time: 3ms
memory: 78300kb

input:

5 4
5 4 2 1

output:

6 4

result:

ok 2 number(s): "6 4"

Test #3:

score: 18
Accepted
time: 14ms
memory: 81032kb

input:

8 4
6 3 2 1

output:

15 4

result:

ok 2 number(s): "15 4"

Test #4:

score: 18
Accepted
time: 12ms
memory: 78392kb

input:

8 6
8 7 5 4 2 1

output:

14 2

result:

ok 2 number(s): "14 2"

Test #5:

score: 18
Accepted
time: 11ms
memory: 79452kb

input:

8 3
8 7 1

output:

22 7

result:

ok 2 number(s): "22 7"

Test #6:

score: 18
Accepted
time: 7ms
memory: 78004kb

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

input:

16 2
6 1

output:

77 15

result:

ok 2 number(s): "77 15"

Test #8:

score: 27
Accepted
time: 22ms
memory: 79228kb

input:

16 8
10 9 8 7 6 5 4 1

output:

57 5

result:

ok 2 number(s): "57 5"

Test #9:

score: 27
Accepted
time: 30ms
memory: 79164kb

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: 27
Accepted
time: 19ms
memory: 82528kb

input:

16 7
10 9 8 6 5 4 1

output:

49 1

result:

ok 2 number(s): "49 1"

Test #11:

score: 27
Accepted
time: 10ms
memory: 78960kb

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: 8ms
memory: 80008kb

input:

22 3
5 3 1

output:

100 1

result:

ok 2 number(s): "100 1"

Test #13:

score: 21
Accepted
time: 7ms
memory: 79288kb

input:

22 1
1

output:

231 1

result:

ok 2 number(s): "231 1"

Test #14:

score: 21
Accepted
time: 64ms
memory: 88584kb

input:

22 4
10 8 3 1

output:

97 4

result:

ok 2 number(s): "97 4"

Test #15:

score: 21
Accepted
time: 85ms
memory: 86640kb

input:

22 5
10 7 6 3 1

output:

92 70

result:

ok 2 number(s): "92 70"

Test #16:

score: 21
Accepted
time: 98ms
memory: 89560kb

input:

22 6
10 9 8 7 3 1

output:

97 1

result:

ok 2 number(s): "97 1"

Test #17:

score: 21
Accepted
time: 158ms
memory: 87492kb

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: 17ms
memory: 80448kb

input:

14 2
10 1

output:

61 210

result:

ok 2 number(s): "61 210"

Test #19:

score: 10
Accepted
time: 13ms
memory: 79876kb

input:

18 2
2 1

output:

117 1

result:

ok 2 number(s): "117 1"

Test #20:

score: 10
Accepted
time: 178ms
memory: 126728kb

input:

30 2
9 1

output:

264 84

result:

ok 2 number(s): "264 84"

Test #21:

score: 10
Accepted
time: 150ms
memory: 112944kb

input:

29 2
9 1

output:

253 36

result:

ok 2 number(s): "253 36"

Test #22:

score: 10
Accepted
time: 41ms
memory: 83896kb

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: 668ms
memory: 173588kb

input:

30 4
10 9 5 1

output:

188 40

result:

ok 2 number(s): "188 40"

Test #24:

score: 24
Accepted
time: 1387ms
memory: 172004kb

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: 24
Accepted
time: 1239ms
memory: 174720kb

input:

30 8
10 9 8 7 4 3 2 1

output:

154 1

result:

ok 2 number(s): "154 1"

Test #26:

score: 24
Accepted
time: 1248ms
memory: 171620kb

input:

30 8
10 8 7 6 5 4 3 1

output:

155 1

result:

ok 2 number(s): "155 1"

Test #27:

score: 24
Accepted
time: 910ms
memory: 173220kb

input:

30 6
10 8 6 4 3 1

output:

150 4

result:

ok 2 number(s): "150 4"

Test #28:

score: 24
Accepted
time: 1519ms
memory: 171364kb

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: 24
Accepted
time: 718ms
memory: 149420kb

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