Submission #222431

# Submission time Handle Problem Language Result Execution time Memory
222431 2020-04-13T07:11:44 Z dwsc Popcount (COCI19_popcount) C++14
30 / 110
6 ms 384 KB
#include <bits/stdc++.h>
using namespace std;
string checkbit(int i){
    return "((A&(1<<"+to_string(i)+"))>>"+to_string(i)+")";
}
string bitshift(int i){
    return "(1<<"+to_string(i)+")";
}
string getmaxint(int n){
    return "((1<<"+to_string(n)+")-1)";
}
int f1(int a,int i){
    return ((a&(1<<i))>>i);
}
int f2(int i){
    return (1<<i);
}
int f3(int i){
    return ((1<<i)-1);
}
int main(){
    int n,k;
    cin >> n >> k;
    //for (int a = 0; a <(1<<n); a++){
    //    int temp = a;
        if (k*4 >= n){
            cout << (n+3)/4 << "\n";
            for (int i = 0; i < n; i+= 4){
                string add = checkbit(i),sub="("+getmaxint(n)+"-"+bitshift(i)+")";
                //int val = f1(a,i),val2 = f3(n)-f2(i);
                for (int j = i+1; j < min(i+4,n); j++){
                    add = "("+add+"+"+checkbit(j)+")";
                    sub = "("+sub+"-"+bitshift(j)+")";
                   // val += f1(a,j);
                   // val2 -= f2(j);
                }
                //val2 = temp&val2;
                //temp = (val+val2);
                sub = "(A&"+sub+")";
                string finalString = "A=("+add+"+"+sub+")";
                cout << finalString << "\n";
            }
        }
       // if(temp != (__builtin_popcount(a))) cout << a << " " << temp << "\n";
       // else cout << temp << "\n";
   // }
}
# Verdict Execution time Memory 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 Correct 5 ms 256 KB Accepted.
6 Correct 4 ms 256 KB Accepted.
7 Correct 5 ms 256 KB Accepted.
8 Correct 4 ms 256 KB Accepted.
9 Correct 5 ms 256 KB Accepted.
10 Correct 5 ms 256 KB Accepted.
11 Correct 5 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.
# Verdict Execution time Memory Grader output
1 Correct 6 ms 384 KB Accepted.
# Verdict Execution time Memory Grader output
1 Correct 4 ms 256 KB Accepted.
2 Correct 5 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 384 KB Accepted.
8 Correct 5 ms 256 KB Accepted.
9 Correct 5 ms 256 KB Accepted.
10 Incorrect 5 ms 256 KB Wrong output format.
11 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 5 ms 256 KB Wrong output format.
2 Halted 0 ms 0 KB -