# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
222460 | dantoh000 | Popcount (COCI19_popcount) | C++14 | 5 ms | 384 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
string tostring(int x){
string s;
if (x == 0) return "0";
while (x){
s += (x%10)+'0';
x /= 10;
}
reverse(s.begin(),s.end());
return s;
}
int main(){
int n,k;
scanf("%d%d",&n,&k);
vector<string> ans;
/*srand(time(NULL));
int A = rand()%(1<<n);
int ch = __builtin_popcount(A);*/
for (;n >= 5; n -= 4){
//printf("A = %d\n",A);
ans.push_back("A=((A>>4)+(((A&1)+(((A&2)>>1)+(((A&4)>>2)+((A&8)>>3))))<<"+tostring(n-4)+"))");
//A=((A>>4)+(((A&1)+(((A&2)>>1)+(((A&4)>>2)+((A&8)>>3))))<<(n-4)));
}
//printf("there are %d bits left\n",n);
if (n == 1){
ans.push_back("A=((A>>1)+(A&1))");
//A=((A>>1)+(A&1));
}
else if (n == 2){
ans.push_back("A=((A>>2)+((A&1)+((A&2)>>1)))");
//A=((A>>2)+((A&1)+((A&2)>>1)));
}
else if (n == 3){
ans.push_back("A=((A>>3)+((A&1)+(((A&2)>>1)+((A&4)>>2))))");
//A=((A>>3)+((A&1)+(((A&2)>>1)+((A&4)>>2))));
}
else if (n == 4){
ans.push_back("A=((A>>4)+((A&1)+(((A&2)>>1)+(((A&4)>>2)+((A&8)>>3)))))");
//A=((A>>4)+((A&1)+(((A&2)>>1)+(((A&4)>>2)+((A&8)>>3)))));
}
printf("%d\n",ans.size());
for (auto x : ans){
cout << x << "\n";
}
//printf("%d %d\n",A,ch);
//assert(A==ch);
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |