結果

問題 No.602 隠されていたゲーム2
ユーザー PachicobuePachicobue
提出日時 2017-12-02 02:34:21
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 56 ms / 2,000 ms
コード長 1,628 bytes
コンパイル時間 2,671 ms
コンパイル使用メモリ 205,192 KB
実行使用メモリ 4,872 KB
最終ジャッジ日時 2023-08-22 05:36:55
合計ジャッジ時間 4,148 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 1 ms
4,376 KB
testcase_12 AC 1 ms
4,380 KB
testcase_13 AC 2 ms
4,380 KB
testcase_14 AC 2 ms
4,376 KB
testcase_15 AC 2 ms
4,376 KB
testcase_16 AC 9 ms
4,376 KB
testcase_17 AC 17 ms
4,380 KB
testcase_18 AC 44 ms
4,820 KB
testcase_19 AC 55 ms
4,872 KB
testcase_20 AC 51 ms
4,824 KB
testcase_21 AC 34 ms
4,824 KB
testcase_22 AC 56 ms
4,780 KB
testcase_23 AC 43 ms
4,780 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

#define VARNAME(x) #x
#define show(x) cerr << #x << " = " << x << endl

using namespace std;
using ll = long long;

template <typename T>
ostream& operator<<(ostream& os, const vector<T>& v)
{
    os << "sz:" << v.size() << "\n[";
    for (const auto& p : v) {
        os << p << ",";
    }
    os << "]\n";
    return os;
}

template <typename S, typename T>
ostream& operator<<(ostream& os, const pair<S, T>& p)
{
    os << "(" << p.first << "," << p.second
       << ")";
    return os;
}


constexpr ll MOD = (ll)1e9 + 7LL;

template <typename T>
constexpr T INF = numeric_limits<T>::max() / 64;

int main()
{
    int N;
    cin >> N;
    vector<ll> d(N);
    vector<ll> odd;
    vector<ll> even;
    for (int i = 0; i < N; i++) {
        cin >> d[i];
        (d[i] % 2 == 0 ? even : odd).push_back(d[i]);
    }
    ll x, y;
    cin >> x >> y;
    const ll dist = abs(x) + abs(y);
    sort(d.begin(), d.end());
    sort(odd.begin(), odd.end());
    sort(even.begin(), even.end());
    if (dist == 0) {
        cout << 0 << endl;
        return 0;
    }
    for (int i = 0; i < N; i++) {
        if (d[i] == dist) {
            cout << 1 << endl;
            return 0;
        }
    }
    if (dist > 2 * d.back()) {
        cout << -1 << endl;
        return 0;
    } else if (dist % 2 == 0) {
        cout << 2 << endl;
        return 0;
    }
    for (const ll e : even) {
        if (upper_bound(odd.begin(), odd.end(), dist + e) - lower_bound(odd.begin(), odd.end(), abs(dist - e))) {
            cout << 2 << endl;
            return 0;
        }
    }
    cout << -1 << endl;

    return 0;
}
0