Submission #199782

# Submission time Handle Problem Language Result Execution time Memory
199782 2020-02-03T10:31:20 Z SamAnd Popcount (COCI19_popcount) C++17
110 / 110
23 ms 380 KB
#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.empty() && 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()
{
    k = min(k, 10);
    cout << k << endl;
    for (int i = 0; i < k; ++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);
        }
        ast = {1};
        for (int j = 0; j < i; ++j)
            ast = gum(ast, ast);
        cout << "A=((";
        tp(v1);
        cout << "&A)+((";
        tp(v2);
        if (v2.empty())
            cout << "&A)>>" << 0 << "))\n";
        else
        {
            cout << "&A)>>";
            tp(ast);
            cout << "))\n";
        }
    }
}

int main()
{
    cin >> n >> k;
    solv4();
    return 0;
}

Compilation message

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)
                     ~~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 5 ms 248 KB Accepted.
2 Correct 4 ms 256 KB Accepted.
3 Correct 5 ms 256 KB Accepted.
4 Correct 5 ms 376 KB Accepted.
5 Correct 5 ms 256 KB Accepted.
6 Correct 5 ms 256 KB Accepted.
7 Correct 5 ms 256 KB Accepted.
8 Correct 5 ms 256 KB Accepted.
9 Correct 5 ms 256 KB Accepted.
10 Correct 5 ms 376 KB Accepted.
11 Correct 6 ms 256 KB Accepted.
12 Correct 5 ms 256 KB Accepted.
13 Correct 5 ms 256 KB Accepted.
14 Correct 6 ms 376 KB Accepted.
# Verdict Execution time Memory Grader output
1 Correct 21 ms 380 KB Accepted.
# Verdict Execution time Memory Grader output
1 Correct 5 ms 376 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 256 KB Accepted.
7 Correct 5 ms 256 KB Accepted.
8 Correct 5 ms 256 KB Accepted.
9 Correct 5 ms 376 KB Accepted.
10 Correct 5 ms 256 KB Accepted.
11 Correct 5 ms 256 KB Accepted.
12 Correct 5 ms 376 KB Accepted.
13 Correct 5 ms 256 KB Accepted.
14 Correct 5 ms 376 KB Accepted.
15 Correct 5 ms 376 KB Accepted.
16 Correct 5 ms 256 KB Accepted.
17 Correct 5 ms 256 KB Accepted.
18 Correct 5 ms 376 KB Accepted.
19 Correct 5 ms 376 KB Accepted.
20 Correct 5 ms 256 KB Accepted.
21 Correct 5 ms 256 KB Accepted.
# Verdict Execution time Memory Grader output
1 Correct 8 ms 256 KB Accepted.
2 Correct 12 ms 376 KB Accepted.
3 Correct 17 ms 256 KB Accepted.
4 Correct 19 ms 376 KB Accepted.
5 Correct 9 ms 256 KB Accepted.
6 Correct 6 ms 256 KB Accepted.
7 Correct 7 ms 376 KB Accepted.
8 Correct 7 ms 256 KB Accepted.
9 Correct 10 ms 376 KB Accepted.
10 Correct 10 ms 376 KB Accepted.
11 Correct 10 ms 256 KB Accepted.
12 Correct 23 ms 256 KB Accepted.