QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#337016#8285. Shell Sortucup-team197#AC ✓840ms18076kbC++141.8kb2024-02-25 01:25:402024-02-25 01:25:41

Judging History

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

  • [2024-02-25 01:25:41]
  • 评测
  • 测评结果:AC
  • 用时:840ms
  • 内存:18076kb
  • [2024-02-25 01:25:40]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod=1e9+7;
int n,m,z;
int d[11],p[35];
int dp[1048576];
int val[1048576];
ll ways[1048576];

int bx[31],pf[31];

int track[31];
int pos[11];
int pen[31],out[31];
int main(){
	ios::sync_with_stdio(false);cin.tie(0);
	cin >> n >> m;
	for(int i=1; i<=m ;i++){
		cin >> d[i];
		d[i]=min(d[i],n);
	}
	z=d[1];z=min(z,n);
	pf[0]=1;
	int ext=0;
	for(int i=0; i<z ;i++){
		bx[i]=(n-i+z-1)/z;
		pf[i+1]=pf[i]*(bx[i]+1);
		ext+=(bx[i])*(bx[i]-1)/2;
		
	}
	ways[0]=1;
	int ans;
	ll wans;
	for(int i=1; i<pf[z] ;i++){
		ll mul=0;
		//cout << "Doing " << i << endl;
		for(int j=0; j<z ;j++){
			int cur=i%pf[j+1]/pf[j];
			pos[j]=j+(cur-1)*z;
			track[j]=0;
			for(int k=j; k<n ;k+=z){
				if(k<j+cur*z) p[k]=0;
				else p[k]=1;
			}
		}
		/*for(int j=0; j<n ;j++) cout << p[j];
		cout << endl;*/
		
		for(int j=0; j<n ;j++) track[j]=0;
		for(int r=2; r<=m ;r++){
			for(int j=0; j<n ;j++) pen[j]=0;
			for(int j=0; j<d[r] ;j++){
				int cnt=0,c0=0;
				for(int k=j; k<n ;k+=d[r]){
					if(p[k]==0) c0++,pen[k]=cnt;
					else cnt++;
				}
				for(int k=j; k<n ;k+=d[r]){
					out[k]=j+(c0-1)*d[r];
				}
				for(int k=j; k<n ;k+=d[r]){
					if(c0-->0) p[k]=0;
					else p[k]=1;
				}
			}
			for(int j=0; j<z ;j++){
				if(pos[j]<0) continue;
				track[j]+=pen[pos[j]];
				pos[j]=out[pos[j]];
			}
		}
		
		dp[i]=-1e9;
		for(int j=0; j<z ;j++){
			int cur=i%pf[j+1]/pf[j];
			if(cur==0) continue;
			if(dp[i]<dp[i-pf[j]]+track[j]){
				dp[i]=dp[i-pf[j]]+track[j];
				ways[i]=ways[i-pf[j]];
			}
			else if(dp[i]==dp[i-pf[j]]+track[j]){
				ways[i]=(ways[i]+ways[i-pf[j]])%mod;
			}
		}
		ans=dp[i];
		wans=ways[i];
		//cout << dp[i] << ' ' << ways[i] << endl;
	}
	cout << ans+ext << ' ' << wans << endl;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

2 2
2 1

output:

1 1

result:

ok 2 number(s): "1 1"

Test #2:

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

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

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

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

input:

8 3
8 7 1

output:

22 7

result:

ok 2 number(s): "22 7"

Test #6:

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

input:

8 1
1

output:

28 1

result:

ok 2 number(s): "28 1"

Test #7:

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

input:

16 2
6 1

output:

77 15

result:

ok 2 number(s): "77 15"

Test #8:

score: 0
Accepted
time: 7ms
memory: 5840kb

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

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: 6ms
memory: 5840kb

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: 1ms
memory: 5760kb

input:

16 4
7 6 2 1

output:

52 9

result:

ok 2 number(s): "52 9"

Test #12:

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

input:

22 3
5 3 1

output:

100 1

result:

ok 2 number(s): "100 1"

Test #13:

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

input:

22 1
1

output:

231 1

result:

ok 2 number(s): "231 1"

Test #14:

score: 0
Accepted
time: 34ms
memory: 6492kb

input:

22 4
10 8 3 1

output:

97 4

result:

ok 2 number(s): "97 4"

Test #15:

score: 0
Accepted
time: 42ms
memory: 6484kb

input:

22 5
10 7 6 3 1

output:

92 70

result:

ok 2 number(s): "92 70"

Test #16:

score: 0
Accepted
time: 48ms
memory: 6548kb

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: 78ms
memory: 10044kb

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: 1ms
memory: 5836kb

input:

14 2
10 1

output:

61 210

result:

ok 2 number(s): "61 210"

Test #19:

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

input:

18 2
2 1

output:

117 1

result:

ok 2 number(s): "117 1"

Test #20:

score: 0
Accepted
time: 66ms
memory: 12184kb

input:

30 2
9 1

output:

264 84

result:

ok 2 number(s): "264 84"

Test #21:

score: 0
Accepted
time: 54ms
memory: 11924kb

input:

29 2
9 1

output:

253 36

result:

ok 2 number(s): "253 36"

Test #22:

score: 0
Accepted
time: 9ms
memory: 6364kb

input:

25 2
8 1

output:

195 8

result:

ok 2 number(s): "195 8"

Test #23:

score: 0
Accepted
time: 340ms
memory: 18032kb

input:

30 4
10 9 5 1

output:

188 40

result:

ok 2 number(s): "188 40"

Test #24:

score: 0
Accepted
time: 761ms
memory: 18016kb

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: 673ms
memory: 18076kb

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: 700ms
memory: 18036kb

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: 526ms
memory: 17948kb

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: 840ms
memory: 18076kb

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: 375ms
memory: 15152kb

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