QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#129737#6512. Completely Multiplicative FunctionSorting#WA 10ms10472kbC++1.4kb2023-07-22 22:46:522023-07-22 22:48:00

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-07-22 22:48:00]
  • 评测
  • 测评结果:WA
  • 用时:10ms
  • 内存:10472kb
  • [2023-07-22 22:46:52]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int iu=1e6;
bool isp[iu+1];
int pf[iu+1];
int pc;
int p[iu+1];

int n,k;


int ans[iu+1];
void solve(){
	cin >> n >> k;
	if(n%2!=k%2){
		cout << "-1\n";
		return;
	}
	k=(k+n)/2;
	double cur=n;
	int sz=0;
	int bn=0;
	for(int i=1; i<=pc ;i++){
		if(p[i]>n) break;
		sz=i;
		if(p[i]*2>n) bn++;
	}
	for(int i=1; i<=n ;i++) ans[i]=1;
	int gd=2;
	while(true){
		int sum=0;
		for(int i=1; i<=n ;i++) sum+=ans[i];
		cout << sum << endl;
		if(sum-bn<=k){//success
			for(int i=n/2+1; i<=n ;i++){
				if(isp[i] && sum>k){
					ans[i]=0;
					sum--;
				}
			}
			for(int i=1; i<=n ;i++) cout << ans[i]*2-1 << ' ';
			cout << '\n';
			return;
		}
		for(int i=gd; i<=n/2 ;i++){
			if(!isp[i]) continue;
			int cur=0;
			for(ll z=i,s=1; z<=n ;z*=i,s*=-1){
				for(int j=z; j<=n ;j+=z) cur+=(ans[j]*2-1)*s;
			}
			//cout << i << ' ' << cur << endl;
			//system("pause");
			if(sum-cur<k || cur<=0){
				++gd;continue;
			}
			++gd;
			for(ll z=i,s=1; z<=n ;z*=i,s*=-1){
				for(int j=z; j<=n ;j+=z) ans[j]=1-ans[j];
			}
			break;
		}
	}
}
int main(){
	ios::sync_with_stdio(false);cin.tie(0);
	for(int i=2; i<=iu ;i++) isp[i]=true;
	for(int i=2; i<=iu ;i++){
		if(!isp[i]) continue;
		p[++pc]=i;
		for(int j=2*i; j<=iu ;j+=i){
			isp[j]=false;
			pf[j]=i;
		}
	}
	int t;cin >> t;while(t--) solve();
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 10ms
memory: 10472kb

input:

4
4 2
10 0
10 1
10 10

output:

4
1 1 -1 1 
10
6
1 -1 1 1 1 -1 -1 -1 1 -1 
-1
10
1 1 1 1 1 1 1 1 1 1 

result:

wrong answer Integer parameter [name=has sol?] equals to 4, violates the range [-1, 1] (test case 1)