답안 #199481

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
199481 2020-02-01T14:32:48 Z SamAnd Lutrija (COCI19_lutrija) C++17
70 / 70
407 ms 504 KB
#include <bits/stdc++.h>
using namespace std;

long long a, b;

bool stgg(long long x)
{
    if (x <= 1)
        return false;
    for (long long i = 2; i * i <= x; ++i)
    {
        if (x % i == 0)
            return false;
    }
    return true;
}

vector<long long> v;

bool c[7][7];

vector<long long> ans;
bool cc[7];
bool dfs(int i)
{
    if (cc[i])
        return false;
    cc[i] = true;
    ans.push_back(v[i]);
    if (v[i] == b && ans.size() > 1)
        return true;
    for (int j = 0; j < v.size(); ++j)
    {
        if (c[i][j])
        {
            if (dfs(j))
                return true;
        }
    }
    ans.pop_back();
    return false;
}

int main()
{
    scanf("%lld%lld", &a, &b);
    if (a == 2 && b == 2)
    {
        printf("3\n2 5 2\n");
        return 0;
    }
    if (stgg(a - 2))
        v.push_back(a - 2);
    v.push_back(a);
    if (stgg(a + 2))
        v.push_back(a + 2);
    if (stgg(b - 2))
        v.push_back(b - 2);
    v.push_back(b);
    if (stgg(b + 2))
        v.push_back(b + 2);
    v.push_back(2);
    for (int i = 0; i < v.size(); ++i)
    {
        for (int j = i + 1; j < v.size(); ++j)
        {
            if (stgg(abs(v[i] - v[j])))
            {
                c[i][j] = c[j][i] = true;
            }
        }
    }
    for (int i = 0; i < v.size(); ++i)
    {
        if (v[i] == a)
        {
            if (dfs(i))
            {
                printf("%d\n", ans.size());
                for (int i = 0; i < ans.size(); ++i)
                    printf("%lld ", ans[i]);
                printf("\n");
                return 0;
            }
            printf("-1\n");
            return 0;
        }
    }
    return 0;
}

Compilation message

lutrija.cpp: In function 'bool dfs(int)':
lutrija.cpp:32:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (int j = 0; j < v.size(); ++j)
                     ~~^~~~~~~~~~
lutrija.cpp: In function 'int main()':
lutrija.cpp:63:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (int i = 0; i < v.size(); ++i)
                     ~~^~~~~~~~~~
lutrija.cpp:65:31: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for (int j = i + 1; j < v.size(); ++j)
                             ~~^~~~~~~~~~
lutrija.cpp:73:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (int i = 0; i < v.size(); ++i)
                     ~~^~~~~~~~~~
lutrija.cpp:79:42: warning: format '%d' expects argument of type 'int', but argument 2 has type 'std::vector<long long int>::size_type {aka long unsigned int}' [-Wformat=]
                 printf("%d\n", ans.size());
                                ~~~~~~~~~~^
lutrija.cpp:80:35: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
                 for (int i = 0; i < ans.size(); ++i)
                                 ~~^~~~~~~~~~~~
lutrija.cpp:46:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%lld%lld", &a, &b);
     ~~~~~^~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 256 KB Output is correct
2 Correct 5 ms 256 KB Output is correct
3 Correct 5 ms 256 KB Output is correct
4 Correct 5 ms 128 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 256 KB Output is correct
2 Correct 5 ms 256 KB Output is correct
3 Correct 6 ms 256 KB Output is correct
4 Correct 5 ms 256 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 376 KB Output is correct
2 Correct 5 ms 376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 256 KB Output is correct
2 Correct 5 ms 376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 256 KB Output is correct
2 Correct 5 ms 256 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 256 KB Output is correct
2 Correct 7 ms 256 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 337 ms 364 KB Output is correct
2 Correct 200 ms 256 KB Output is correct
3 Correct 407 ms 256 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 332 ms 504 KB Output is correct
2 Correct 198 ms 380 KB Output is correct
3 Correct 293 ms 504 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 365 ms 504 KB Output is correct
2 Correct 192 ms 256 KB Output is correct
3 Correct 270 ms 504 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 280 ms 376 KB Output is correct
2 Correct 149 ms 256 KB Output is correct
3 Correct 98 ms 376 KB Output is correct