답안 #332240

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
332240 2020-12-01T18:36:48 Z IgorI Devil's Share (RMI19_devil) C++17
0 / 100
157 ms 1796 KB
#include <bits/stdc++.h>

using namespace std;

string req(int c1, int c2)
{
    if (c1 == 0 && c2 == 0)
    {
        return "";
    }
    assert(c1 >= 1);
    if (c2 == 0)
    {
        return string(c1, '1');
    }
    if (c2 <= c1)
    {
        int k = c1 / c2;
        string sss = "";
        while (c2)
        {
            sss += "2";
            for (int j = 0; j < k; j++)
            {
                sss += "1";
                c1--;
            }
            c2--;
        }
        while (c1)
        {
            sss += "1";
            c1--;
        }
        return sss;
    }
    //cout << "ask : " << c1 << " " << c2 << endl;
    for (int k = 2; ; k++)
    {
        int blocks = (c2 + k - 1) / k;
        if (blocks <= c1)
        {
            //cout << k << " " << blocks << endl;
            assert(2 * blocks > c1);
            if (c2 != blocks * k)
            {
                string g(k, '2');
                g[k - 1] = '1';
                return req(c1 - 1, c2 - k + 1) + g;
            }
            else
            {
                string g(k + 1, '2');
                g[k] = '1';
                return req(c1 - 1, c2 - k) + g;
            }
        }
    }
}

void solve()
{
    int k;
    cin >> k;
    vector<int> d(10);
    for (int i = 1; i <= 9; i++)
        cin >> d[i];
    int len = accumulate(d.begin(), d.end(), 0);
    if (d[1] == 0)
    {
        cout << string(len, '2') << "\n";
        return;
    }
    string res(k - 1, '0');
    for (int i = k - 2; i >= 0; i--)
        if (d[2])
            res[i] = '2', d[2]--;
        else
            res[i] = '1', d[1]--;

    cout << req(d[1], d[2]) << res << "\n";
}

int main()
{
    int t;
    cin >> t;
    while (t--)
    {
        solve();
    }
}
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1 ms 492 KB Execution killed with signal 6 (could be triggered by violating memory limits)
# 결과 실행 시간 메모리 Grader output
1 Incorrect 157 ms 1796 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 120 ms 1772 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1 ms 492 KB Execution killed with signal 6 (could be triggered by violating memory limits)