답안 #222460

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
222460 2020-04-13T07:46:57 Z dantoh000 Popcount (COCI19_popcount) C++14
30 / 110
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 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

popcount.cpp: In function 'int main()':
popcount.cpp:42:29: warning: format '%d' expects argument of type 'int', but argument 2 has type 'std::vector<std::__cxx11::basic_string<char> >::size_type {aka long unsigned int}' [-Wformat=]
     printf("%d\n",ans.size());
                   ~~~~~~~~~~^
popcount.cpp:15:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d%d",&n,&k);
     ~~~~~^~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 256 KB Accepted.
2 Correct 5 ms 384 KB Accepted.
3 Correct 5 ms 256 KB Accepted.
4 Correct 4 ms 256 KB Accepted.
5 Correct 5 ms 256 KB Accepted.
6 Correct 4 ms 384 KB Accepted.
7 Correct 5 ms 256 KB Accepted.
8 Correct 5 ms 256 KB Accepted.
9 Correct 5 ms 256 KB Accepted.
10 Correct 5 ms 256 KB Accepted.
11 Correct 4 ms 256 KB Accepted.
12 Correct 5 ms 256 KB Accepted.
13 Correct 5 ms 256 KB Accepted.
14 Correct 5 ms 256 KB Accepted.
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 384 KB Accepted.
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 256 KB Accepted.
2 Correct 4 ms 256 KB Accepted.
3 Correct 5 ms 256 KB Accepted.
4 Correct 5 ms 256 KB Accepted.
5 Correct 5 ms 256 KB Accepted.
6 Correct 5 ms 384 KB Accepted.
7 Correct 5 ms 256 KB Accepted.
8 Correct 5 ms 256 KB Accepted.
9 Correct 5 ms 256 KB Accepted.
10 Incorrect 4 ms 256 KB Incorrect number of commands.
11 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 4 ms 384 KB Incorrect number of commands.
2 Halted 0 ms 0 KB -