Submission #199773

#TimeUsernameProblemLanguageResultExecution timeMemory
199773SamAndPopcount (COCI19_popcount)C++17
0 / 110
18 ms376 KiB
#include <bits/stdc++.h> using namespace std; int n, k; vector<int> gum(vector<int> a, vector<int> b) { vector<int> ans; reverse(a.begin(), a.end()); reverse(b.begin(), b.end()); while (a.size() < b.size()) a.push_back(0); while (b.size() < a.size()) b.push_back(0); int m = 0; for (int i = 0; i < a.size(); ++i) { ans.push_back((a[i] + b[i] + m) % 10); m = (a[i] + b[i] + m) / 10; } ans.push_back(m); while (ans.back() == 0) ans.pop_back(); reverse(ans.begin(), ans.end()); return ans; } void tp(vector<int> v) { if (v.empty()) v.push_back(0); for (int i = 0; i < v.size(); ++i) cout << v[i]; } void solv4() { int q; for (int i = 0; i < k; ++i) { for (int j = 0; j < n; ++j) { if ((j & (1 << i))) { q = i; break; } } if (q != i) break; } ++q; cout << q << endl; for (int i = 0; i < q; ++i) { vector<int> v1, v2; vector<int> ast = {1}; for (int j = 0; j < n; ++j) { if ((j & (1 << i)) == 0) { v1 = gum(v1, ast); } else { v2 = gum(v2, ast); } ast = gum(ast, ast); } cout << "A=(("; tp(v1); cout << "&A)+(("; tp(v2); cout << "&A)>>" << (i + 1) << "))\n"; } } int main() { cin >> n >> k; if (n == 1) { cout << "0\n"; return 0; } solv4(); return 0; }

Compilation message (stderr)

popcount.cpp: In function 'std::vector<int> gum(std::vector<int>, std::vector<int>)':
popcount.cpp:16:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (int i = 0; i < a.size(); ++i)
                     ~~^~~~~~~~~~
popcount.cpp: In function 'void tp(std::vector<int>)':
popcount.cpp:32:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (int i = 0; i < v.size(); ++i)
                     ~~^~~~~~~~~~
popcount.cpp: In function 'void solv4()':
popcount.cpp:38:9: warning: 'q' may be used uninitialized in this function [-Wmaybe-uninitialized]
     int q;
         ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...