Submission #40203374


Source Code Expand

#include <iostream>
#include <set>
#include <vector>

namespace {
    using Num = long long int;
    using Diffs = std::vector<Num>;
    using Nums = std::set<Num>;
}

void go(Num base, const Diffs& diffs, Nums& tos) {
    tos.insert(base);

    for(const auto& diff : diffs) {
        Nums candidates;
        for(const auto& from : tos) {
            candidates.insert(from + diff);
            candidates.insert(from - diff);
        }

        std::swap(candidates, tos);
    }

    return;
}

void solve(std::istream& is, std::ostream& os) {
    Num n {0};
    Num x {0};
    Num y {0};
    is >> n >> x >> y;

    std::vector<Num> odds;
    std::vector<Num> evens;
    Num base_x {0};

    for(decltype(n) i{0}; i<n; ++i) {
        Num a {0};
        is >> a;
        if ((i & 1) > 0) {
            odds.push_back(a);
        } else {
            if (i == 0) {
                base_x = a;
            } else {
                evens.push_back(a);
            }
        }
    }

    Nums tos_odd;
    Nums tos_even;
    go(0LL, odds, tos_odd);
    go(base_x, evens, tos_even);

    if ((tos_even.find(x) != tos_even.end()) && (tos_odd.find(y) != tos_odd.end())) {
        os << "Yes\n";
    } else {
        os << "No\n";
    }

    return;
}

int main(void) {
    solve(std::cin, std::cout);
    return 0;
}

Submission Info

Submission Time
Task D - Robot Arms 2
User zettsut
Language C++ (GCC 9.2.1)
Score 400
Code Size 1381 Byte
Status AC
Exec Time 144 ms
Memory 4044 KiB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 400 / 400
Status
AC × 5
AC × 27
Set Name Test Cases
Sample 00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt, 00_sample_03.txt, 00_sample_04.txt
All 00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt, 00_sample_03.txt, 00_sample_04.txt, 01_random_00.txt, 01_random_01.txt, 01_random_02.txt, 01_random_03.txt, 01_random_04.txt, 01_random_05.txt, 01_random_06.txt, 01_random_07.txt, 01_random_08.txt, 01_random_09.txt, 02_corner_00.txt, 02_corner_01.txt, 03_handmade_00.txt, 03_handmade_01.txt, 03_handmade_02.txt, 03_handmade_03.txt, 03_handmade_04.txt, 03_handmade_05.txt, 03_handmade_06.txt, 03_handmade_07.txt, 03_handmade_08.txt, 03_handmade_09.txt
Case Name Status Exec Time Memory
00_sample_00.txt AC 8 ms 3580 KiB
00_sample_01.txt AC 2 ms 3452 KiB
00_sample_02.txt AC 2 ms 3500 KiB
00_sample_03.txt AC 2 ms 3456 KiB
00_sample_04.txt AC 2 ms 3432 KiB
01_random_00.txt AC 73 ms 3656 KiB
01_random_01.txt AC 110 ms 3848 KiB
01_random_02.txt AC 10 ms 3632 KiB
01_random_03.txt AC 117 ms 3844 KiB
01_random_04.txt AC 100 ms 3888 KiB
01_random_05.txt AC 113 ms 3896 KiB
01_random_06.txt AC 52 ms 3712 KiB
01_random_07.txt AC 113 ms 3852 KiB
01_random_08.txt AC 11 ms 3484 KiB
01_random_09.txt AC 121 ms 3928 KiB
02_corner_00.txt AC 115 ms 3884 KiB
02_corner_01.txt AC 115 ms 3832 KiB
03_handmade_00.txt AC 144 ms 3872 KiB
03_handmade_01.txt AC 142 ms 4044 KiB
03_handmade_02.txt AC 22 ms 3668 KiB
03_handmade_03.txt AC 23 ms 3528 KiB
03_handmade_04.txt AC 69 ms 3744 KiB
03_handmade_05.txt AC 53 ms 3704 KiB
03_handmade_06.txt AC 43 ms 3548 KiB
03_handmade_07.txt AC 46 ms 3584 KiB
03_handmade_08.txt AC 2 ms 3436 KiB
03_handmade_09.txt AC 2 ms 3560 KiB