Submission #291670

#TimeUsernameProblemLanguageResultExecution timeMemory
291670kingfran1907Popcount (COCI19_popcount)C++14
0 / 110
1 ms384 KiB
#include <bits/stdc++.h> #define X first #define Y second using namespace std; typedef long long llint; const int maxn = 2e5+10; 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< int > v; void rek(int x) { if (x == v.size() - 1) printf("(1<<%d)", v[x]); else { printf("((1<<%d)+", v[x]); rek(x + 1); printf(")"); } } int main() { scanf("%d%d", &n, &k); int log = 0; int tren = 1; while (tren < n) log++, tren *= 2; printf("%d\n", log); for (int i = 0; i < log; i++) { int ac = (1 << i); printf("A=("); printf("(A&"); v.clear(); for (int j = 0; j < n; j += ac * 2) { for (int l = 0; l < ac; l++) { if (l + j >= n) break; v.push_back(j + l); } } rek(0); printf(")+"); v.clear(); for (int j = ac; j < n; j += ac * 2) { int l = min(n, j + ac); if (l == n) { printf("((A&"); for (int x = j; x < l; x++) v.push_back(x); rek(0); printf(")>>%d)", ac); } else printf("((A&((1<<%d)-(1<<%d)))>>%d)", l, j, ac); if (j + ac * 2 < n) printf("+"); } printf(")\n"); } return 0; }

Compilation message (stderr)

popcount.cpp: In function 'void rek(int)':
popcount.cpp:20:8: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   20 |  if (x == v.size() - 1) printf("(1<<%d)", v[x]);
      |      ~~^~~~~~~~~~~~~~~
popcount.cpp: In function 'int main()':
popcount.cpp:29:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   29 |  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...