Submission #51565

# Submission time Handle Problem Language Result Execution time Memory
51565 2018-06-18T15:55:05 Z Kubalionzzale OBELISK (NOI14_obelisk) C++14
5 / 25
743 ms 49552 KB
#include <iostream>

#define int long long int

int abss(int x)
{
    if (x < 0)
        return -x;
    else
        return x;
}

int calc(std::pair<int, int> from, std::pair<int, int> to, int m)
{
    ++m;
    int length = abss(from.first - to.first);
    int overfirst = ((length / m) + 1) * m;
    int underfirst = (length / m) * m;
    int val = length / m;
    int oneover = abss(overfirst - length);
    int oneunder = abss(underfirst - length);

//    std::cout << firstDiff << " ";

    int length2 = abss(from.second - to.second);
    int overfirst2 = ((length / m) + 1) * m;
    int underfirst2 = (length / m) * m;
    int val2 = length / m;
    int oneover2 = abss(overfirst2 - length2);
    int oneunder2 = abss(underfirst2 - length2);

    int min = 1e15;
    //OVER OVER

    min = std::min(min, abss(overfirst - length) + abss(overfirst2 - length2) + ((length / m) + 1LL) * 2LL + ((length2 / m) + 1LL) * 2LL);
    std::cout << min << " ";

    //UNDER OVER
    if (val > 0 || length == 0)
    {
        min = std::min(min, oneunder + oneover2 + val + ((length2 / m) + 1LL) * 2LL);
    }
    else
    {
        min = std::min(min, oneunder + oneover2 + val + ((length2 / m) + 1LL) * 2LL + 2LL);
    }
    std::cout << min << " ";

    //OVER UNDER
    if (val2 > 0 || length2 == 0)
    {
        min = std::min(min, oneover + oneunder2 + ((length / m) + 1LL) * 2LL + val2);
    }
    else
    {
        min = std::min(min, oneover + oneunder2 + ((length / m) + 1LL) * 2LL + val2 + 2LL);
    }

    std::cout << min << " ";

    //UNDER UNDER
    int add = 4LL;
    if (val > 0 || length == 0)
        add -= 2;
    if (val2 > 0 || length2 == 0)
        add -= 2;

    min = std::min(min, oneunder + oneunder2 + val + val2 + add);
    std::cout << min << " ";

    return min;
}

main()
{
    int k, m;
    std::cin >> k >> m;

    std::pair<int, int> hole[510][110];
    int mini[510][110];
    int holeNumber[510];

    std::pair<int, int> start, ende;
    std::cin >> start.first >> start.second >> ende.first >> ende.second;
    holeNumber[0] = 1;
    holeNumber[k] = 1;
    hole[0][0].first = start.first;
    hole[0][0].second = start.second;
    hole[k][0].first = ende.first;
    hole[k][0].second = ende.second;
    mini[0][0] = 0;
    mini[k][0] = 1e15;

    for (int i = 1; i <= k - 1; ++i)
    {
        std::cin >> holeNumber[i];
        for (int j = 0; j < holeNumber[i]; ++j)
        {
            mini[i][j] = 1e15;
            std::cin >> hole[i][j].first >> hole[i][j].second;
        }
    }

    if (m == 1)
    {
        for (int i = 1; i <= k; ++i)
        {
            for (int j = 0; j < holeNumber[i]; ++j)
            {
                for (int q = 0; q < holeNumber[i - 1]; ++q)
                {
                    int val = abss(hole[i][j].first - hole[i - 1][q].first) + abss(hole[i][j].second - hole[i - 1][q].second);
                    mini[i][j] = std::min(mini[i][j], val + mini[i - 1][q]);
                }
            }
        }

        std::cout << mini[k][0];
        return 0;
    }

    for (int i = 1; i <= k; ++i)
    {
        for (int j = 0; j < holeNumber[i]; ++j)
        {
            for (int q = 0; q < holeNumber[i - 1]; ++q)
            {
                int val = calc(hole[i][j], hole[i - 1][q], m);
         //       std::cout << val << " " << j << " " << q << "\n";
                mini[i][j] = std::min(mini[i][j], val + mini[i - 1][q]);
            }
        }
    }

    std::cout << mini[k][0];
}

Compilation message

obelisk.cpp:74:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
 main()
      ^
# Verdict Execution time Memory Grader output
1 Correct 3 ms 1144 KB Output is correct
2 Correct 3 ms 1380 KB Output is correct
3 Correct 3 ms 1448 KB Output is correct
4 Correct 3 ms 1448 KB Output is correct
5 Correct 3 ms 1448 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 9 ms 1544 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 511 ms 18216 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 743 ms 49552 KB Output isn't correct
2 Halted 0 ms 0 KB -