Submission #222452

#TimeUsernameProblemLanguageResultExecution timeMemory
222452dwscPopcount (COCI19_popcount)C++14
65 / 110
5 ms384 KiB
#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; 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)+")"; for (int j = i+1; j < min(i+4,n); j++){ add = "("+add+"+"+checkbit(j)+")"; sub = "("+sub+"-"+bitshift(j)+")"; } sub = "(A&"+sub+")"; string finalString = "A=("+add+"+"+sub+")"; cout << finalString << "\n"; } } else{ //for (int a = 4; a < (1<<n); a++){ int numboxes = n,boxsize = 1; //int temp = a; //cout << temp << "hi\n"; int val = 0,tempn = n; while (tempn != 1){ val++; tempn = (tempn+1)/2; } cout << val << "\n"; while (numboxes != 1){ string bigbox = "0",smallbox = "0"; int addto = 0; int num = 0; //int bigval = 0,smallval = 0; for (int i = 0; i < n; i++){ num++; if (num > boxsize){ num-=boxsize; addto = 1-addto; } if (addto){ //bigval += f2(i); bigbox = "("+bigbox+"+"+bitshift(i)+")"; } else{ //smallval += f2(i); smallbox = "("+smallbox+"+"+bitshift(i)+")"; } } string finalstring = "A=(((A&"+bigbox+")>>"+to_string(boxsize)+")+(A&"+smallbox+"))"; cout << finalstring << "\n"; //temp = ((temp&bigval)>>boxsize)+(temp&smallval); numboxes = (numboxes+1)/2; boxsize *= 2; } //if (temp != __builtin_popcount(a)) cout << "hi\n"; //} } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...