# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
222444 | 2020-04-13T07:23:37 Z | dantoh000 | Popcount (COCI19_popcount) | C++14 | 5 ms | 384 KB |
#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 T = rand()%(1<<n); //int ch = __builtin_popcount(T); int num = n/4; for (int i = 1; i <= num; i++){ //printf("T = %d\n",T); //printf("add %d shift %d\n",(T&1)+((T&2)>>1)+((T&4)>>2)+((T&8)>>3),(n-i*4-1)); if (n-i*4-1 == 0){ ans.push_back("A=((A>>4)+((A&1)+(((A&2)>>1)+(((A&4)>>2)+((A&8)>>3)))))"); } else ans.push_back("A=((A>>4)+(((A&1)+(((A&2)>>1)+(((A&4)>>2)+((A&8)>>3))))<<"+tostring(n-i*4-1)+"))"); //T =(T>>4)+(((T&1)+((T&2)>>1)+((T&4)>>2)+((T&8)>>3))<<(n-i*4-1)); } n %= 4; //printf("there are %d bits left\n",n); if (n == 2){ ans.push_back("A=((A>>1)+(A&1))"); //T=(T>>1)+(T&1); } else if (n == 3){ ans.push_back("A=((A>>2)+((A&1)+((A&2)>>1)))"); //T=(T>>2)+(T&1)+((T&2)>>1); } /*else if (n%4 == 2){ ans.push_back("A=(A>>3)+(A&1)+((A&2)>>1)+((A&4)>>2)"); T=(T>>3)+(T&1)+(T&2)+(T&4); } else if (n%4 == 3){ ans.push_back("A=(A>>4)+(A&1)+((A&2)>>1)+((A&4)>>2)+((A&8)>>3)"); T=(T>>4)+(T&1)+(T&2)+(T&4)+(T&8); }*/ printf("%d\n",ans.size()); for (auto x : ans){ cout << x << "\n"; } //printf("%d %d\n",T,ch); //assert(T==ch); }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 5 ms | 256 KB | Accepted. |
2 | Correct | 4 ms | 256 KB | Accepted. |
3 | Incorrect | 4 ms | 256 KB | Wrong command format. |
4 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Incorrect | 5 ms | 384 KB | Wrong command format. |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 4 ms | 256 KB | Accepted. |
2 | Correct | 5 ms | 256 KB | Accepted. |
3 | Correct | 4 ms | 256 KB | Accepted. |
4 | Correct | 5 ms | 256 KB | Accepted. |
5 | Incorrect | 5 ms | 384 KB | Wrong command format. |
6 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Incorrect | 4 ms | 384 KB | Incorrect number of commands. |
2 | Halted | 0 ms | 0 KB | - |