Submission #648259

#TimeUsernameProblemLanguageResultExecution timeMemory
648259kingfran1907Popcount (COCI19_popcount)C++14
110 / 110
5 ms340 KiB
#include <bits/stdc++.h> #define X first #define Y second using namespace std; typedef long long llint; const int maxn = 510; const int base = 31337; const int mod = 1e9+7; const int inf = 0x3f3f3f3f; const int logo = 20; const int off = 1 << logo; const int treesiz = off << 1; int n, k; vector< string > sol; string pot[maxn]; string add(string a, string b) { while (a.size() < b.size()) a.push_back('0'); while (b.size() < a.size()) b.push_back('0'); int car = 0; string out; for (int i = 0; i < a.size(); i++) { int tren = (int)a[i] + b[i] - 2 * '0' + car; out.push_back((tren % 10) + '0'); car = tren / 10; } if (car > 0) out.push_back(car + '0'); while (out.back() == '0') out.pop_back(); return out; } string conv(int x) { if (x == 0) return "0"; string out; while (x > 0) { out.push_back((x % 10) + '0'); x /= 10; } reverse(out.begin(), out.end()); return out; } int main() { scanf("%d%d", &n, &k); pot[0] = "1"; for (int i = 1; i < n; i++) pot[i] = add(pot[i - 1], pot[i - 1]); for (int i = 1; i < n; i *= 2) { string num = "0"; string comp = "0"; for (int j = 0; j < n; j++) { if (j & i) num = add(num, pot[j]); else comp = add(comp, pot[j]); } reverse(num.begin(), num.end()); reverse(comp.begin(), comp.end()); string tren = "A=((A&" + comp + ")+((A&" + num + ")>>" + conv(i) + "))"; sol.push_back(tren); } cout << sol.size() << "\n"; for (string tren : sol) cout << tren << "\n"; return 0; }

Compilation message (stderr)

popcount.cpp: In function 'std::string add(std::string, std::string)':
popcount.cpp:26:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   26 |  for (int i = 0; i < a.size(); i++) {
      |                  ~~^~~~~~~~~~
popcount.cpp: In function 'int main()':
popcount.cpp:48:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   48 |  scanf("%d%d", &n, &k);
      |  ~~~~~^~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...