QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#337003#8285. Shell Sortucup-team197#WA 0ms5732kbC++141.8kb2024-02-25 00:58:512024-02-25 00:58:52

Judging History

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

  • [2024-02-25 00:58:52]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:5732kb
  • [2024-02-25 00:58:51]
  • 提交

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[11];
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];
	}
	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]){
					if(c0-->0) p[k]=0;
					else p[k]=1;
					out[k]=j+(c0-1)*d[r];
				}
			}
			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: 0ms
memory: 5616kb

input:

2 2
2 1

output:

1 1

result:

ok 2 number(s): "1 1"

Test #2:

score: -100
Wrong Answer
time: 0ms
memory: 5732kb

input:

5 4
5 4 2 1

output:

2 4

result:

wrong answer 1st numbers differ - expected: '6', found: '2'