답안 #215525

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
215525 2020-03-26T11:21:52 Z SamAnd ASM (LMIO18_asm) C++17
0 / 100
6 ms 640 KB
#include <bits/stdc++.h>
using namespace std;
#define m_p make_pair
const int N = 55;

int n;
long long a[N], b[N];

vector<pair<char, long long> > ans;

vector<int> lltov(long long x)
{
    vector<int> v;
    if (x == 0)
        v.push_back(0);
    while (x)
    {
        v.push_back(x % 10);
        x /= 10;
    }
    reverse(v.begin(), v.end());
    return v;
}

int main()
{
    scanf("%d", &n);
    for (int i = 1; i <= n; ++i)
    {
        scanf("%lld%lld", &a[i], &b[i]);
    }
    vector<int> v = lltov(b[1]);
    for (int x = 0; x < (1 << v.size()); ++x)
    {
        if (!(x & (1 << 0)))
            continue;
        bool z = true;
        vector<pair<char, long long> > yans;
        long long s = a[1];
        vector<int> u;
        long long uu = 0;
        u.push_back(v[0]);
        uu = v[0];
        for (int i = 1; i < v.size(); ++i)
        {
            if ((x & (1 << i)))
            {
                if (u[0] == 0)
                {
                    if (u.size() > 1)
                    {
                        z = false;
                        break;
                    }
                    if (s == 0)
                    {
                        yans.push_back(m_p('p', -1));
                    }
                    else
                    {
                        yans.push_back(m_p('m', 0));
                        yans.push_back(m_p('p', -1));
                    }
                }
                else
                {
                    if (s > uu)
                    {
                        z = false;
                        break;
                    }
                    if (uu / s != 1)
                        yans.push_back(m_p('m', uu / s));
                    if (uu % s != 0)
                        yans.push_back(m_p('a', uu % s));
                    yans.push_back(m_p('p', -1));
                }
                s = uu;
                u.clear();
                u.push_back(v[i]);
                uu = v[i];
            }
            else
            {
                u.push_back(v[i]);
                uu = uu * 10 + v[i];
            }
        }
        for (int i = 0; i < 1; ++i)
        {
            if (u[0] == 0)
            {
                if (u.size() > 1)
                {
                    z = false;
                    break;
                }
                if (s == 0)
                {
                    yans.push_back(m_p('p', -1));
                }
                else
                {
                    yans.push_back(m_p('m', 0));
                    yans.push_back(m_p('p', -1));
                }
            }
            else
            {
                if (s > uu)
                {
                    z = false;
                    break;
                }
                if (uu / s != 1)
                    yans.push_back(m_p('m', uu / s));
                if (uu % s != 0)
                    yans.push_back(m_p('a', uu % s));
                yans.push_back(m_p('p', -1));
            }
        }
        if (!z)
            continue;
        for (int i = 1; i <= n; ++i)
        {
            long long s = a[i];
            vector<int> u;
            for (int j = 0; j < yans.size(); ++j)
            {
                if (yans[j].first == 'p')
                {
                    vector<int> v = lltov(s);
                    for (int i = 0; i < v.size(); ++i)
                        u.push_back(v[i]);
                }
                else if (yans[j].first == 'm')
                {
                    long double bb = b[i];
                    if (s > bb / yans[j].second)
                    {
                        z = false;
                        break;
                    }
                    s *= yans[j].second;
                }
                else
                {
                    s += yans[j].second;
                    if (s > b[i])
                    {
                        z = false;
                        break;
                    }
                }
            }
            if (!z)
                break;
            vector<int> v = lltov(b[i]);
            if (u.size() != v.size())
            {
                z = false;
                break;
            }
            for (int i = 0; i < u.size(); ++i)
            {
                if (u[i] != v[i])
                {
                    z = false;
                    break;
                }
            }
            if (!z)
            {
                break;
            }
        }
        if (z)
        {
            if (ans.empty() || yans.size() < ans.size())
                ans = yans;
        }
    }
    if (ans.empty())
        printf("-1\n");
    else
    {
        printf("%d\n", ans.size());
        for (int i = 0; i < ans.size(); ++i)
        {
            if (ans[i].first == 'p')
                printf("print\n");
            else if (ans[i].first == 'm')
                printf("multiply %lld\n", ans[i].second);
            else
                printf("add %lld\n", ans[i].second);
        }
    }
    return 0;
}

Compilation message

asm.cpp: In function 'int main()':
asm.cpp:44:27: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for (int i = 1; i < v.size(); ++i)
                         ~~^~~~~~~~~~
asm.cpp:128:31: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
             for (int j = 0; j < yans.size(); ++j)
                             ~~^~~~~~~~~~~~~
asm.cpp:133:39: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
                     for (int i = 0; i < v.size(); ++i)
                                     ~~^~~~~~~~~~
asm.cpp:164:31: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
             for (int i = 0; i < u.size(); ++i)
                             ~~^~~~~~~~~~
asm.cpp:187:34: warning: format '%d' expects argument of type 'int', but argument 2 has type 'std::vector<std::pair<char, long long int> >::size_type {aka long unsigned int}' [-Wformat=]
         printf("%d\n", ans.size());
                        ~~~~~~~~~~^
asm.cpp:188:27: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for (int i = 0; i < ans.size(); ++i)
                         ~~^~~~~~~~~~~~
asm.cpp:27:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d", &n);
     ~~~~~^~~~~~~~~~
asm.cpp:30:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%lld%lld", &a[i], &b[i]);
         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 332 KB Output is correct
2 Incorrect 6 ms 512 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 512 KB Output is correct
2 Correct 5 ms 512 KB Output is correct
3 Incorrect 5 ms 384 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 512 KB Output is correct
2 Incorrect 5 ms 384 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 6 ms 640 KB Execution killed with signal 8 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -