답안 #199769

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
199769 2020-02-03T09:27:23 Z SamAnd Popcount (COCI19_popcount) C++17
0 / 110
198 ms 528 KB
#include <bits/stdc++.h>
using namespace std;

int n, k;

void solv1()
{
    cout << k << endl;
    for (int i = 1; i <= k; ++i)
    {
        cout << "A=((A-(A&";
        cout << "(1<<" << i << ")))";
        cout << "+((A&";
        cout << "(1<<" << i << "))";
        cout << ">>" << i << "))\n";
    }
}

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(const vector<int>& v)
{
    for (int i = 0; i < v.size(); ++i)
        cout << v[i];
}

void solv4()
{
    cout << k << endl;
    for (int i = 1; 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);
        }
        cout << "A=((";
        tp(v1);
        cout << "&A)+((";
        tp(v2);
        cout << "&A)>>" << i << "))\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:29: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(const std::vector<int>&)':
popcount.cpp:43:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (int i = 0; i < v.size(); ++i)
                     ~~^~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 5 ms 256 KB Wrong command format.
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 198 ms 528 KB Wrong command format.
# 결과 실행 시간 메모리 Grader output
1 Incorrect 5 ms 376 KB Wrong command format.
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 8 ms 256 KB Wrong command format.
2 Halted 0 ms 0 KB -