Submission #222612

# Submission time Handle Problem Language Result Execution time Memory
222612 2020-04-13T12:29:35 Z jamielim Popcount (COCI19_popcount) C++14
0 / 110
56 ms 512 KB
#include <bits/stdc++.h>
using namespace std;

string precomp[505];
int n,k;

string add(string a,string b){
	string ans="";
	int carry=0;
	int la=(int)a.length(),lb=(int)b.length();
	if(la>lb){
		swap(la,lb);
		swap(a,b);
	}
	for(int i=0;i<la;i++){
		int A=a[la-i-1]-'0',B=b[lb-i-1]-'0';
		ans=ans+(char)((A+B+carry)%10+'0');
		if(A+B+carry>=10)carry=1;
		else carry=0;
	}
	for(int i=la;i<lb;i++){
		int B=b[lb-i-1]-'0'; //A=0
		ans=ans+(char)((B+carry)%10+'0');
		if(B+carry>=10)carry=1;
		else carry=0;
	}
	if(carry==1)ans=ans+"1";
	reverse(ans.begin(),ans.end());
	return ans;
}

string lol(long long seglen,int parity){
	string ans="0";
	if(parity==0){
		for(int i=0;i<n;i++){
			if((i/seglen)%2==0)ans=add(ans,precomp[i]);
		}
	}else{
		for(int i=0;i<n;i++){
			if((i/seglen)%2==1)ans=add(ans,precomp[i]);
		}
	}
	return ans;
}

int main(){
	precomp[0]="1";
	for(int i=1;i<505;i++){
		precomp[i]=add(precomp[i-1],precomp[i-1]);
	}
	scanf("%d%d",&n,&k);
	for(long long i=0;i<k;i++){
		if((1LL<<i)>=n)break;
		string s1=lol(1LL<<i,0),s2=lol(1LL<<i,1);
		printf("A=((A&%s)+((A&%s)>>%lld))\n",s1.c_str(),s2.c_str(),(1LL<<i));
	}
}

Compilation message

popcount.cpp: In function 'int main()':
popcount.cpp:51:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d%d",&n,&k);
  ~~~~~^~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 10 ms 384 KB Wrong output format.
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 56 ms 384 KB Wrong output format.
# Verdict Execution time Memory Grader output
1 Incorrect 10 ms 384 KB Wrong output format.
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 14 ms 512 KB Wrong output format.
2 Halted 0 ms 0 KB -