結果

問題 No.602 隠されていたゲーム2
ユーザー PachicobuePachicobue
提出日時 2017-12-02 02:34:21
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 57 ms / 2,000 ms
コード長 1,628 bytes
コンパイル時間 2,176 ms
コンパイル使用メモリ 208,044 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-05-09 11:32:22
合計ジャッジ時間 3,307 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,812 KB
testcase_01 AC 3 ms
6,944 KB
testcase_02 AC 3 ms
6,940 KB
testcase_03 AC 2 ms
6,940 KB
testcase_04 AC 3 ms
6,940 KB
testcase_05 AC 3 ms
6,940 KB
testcase_06 AC 2 ms
6,940 KB
testcase_07 AC 3 ms
6,940 KB
testcase_08 AC 3 ms
6,940 KB
testcase_09 AC 3 ms
6,940 KB
testcase_10 AC 2 ms
6,944 KB
testcase_11 AC 2 ms
6,940 KB
testcase_12 AC 2 ms
6,940 KB
testcase_13 AC 3 ms
6,940 KB
testcase_14 AC 2 ms
6,940 KB
testcase_15 AC 3 ms
6,944 KB
testcase_16 AC 10 ms
6,944 KB
testcase_17 AC 18 ms
6,944 KB
testcase_18 AC 45 ms
6,944 KB
testcase_19 AC 55 ms
6,940 KB
testcase_20 AC 54 ms
6,940 KB
testcase_21 AC 35 ms
6,940 KB
testcase_22 AC 57 ms
6,940 KB
testcase_23 AC 46 ms
6,940 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