結果

問題 No.602 隠されていたゲーム2
ユーザー PachicobuePachicobue
提出日時 2017-12-02 02:32:22
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,856 bytes
コンパイル時間 2,359 ms
コンパイル使用メモリ 207,812 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-05-06 00:48:06
合計ジャッジ時間 3,664 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 2 ms
5,376 KB
testcase_08 WA -
testcase_09 AC 2 ms
5,376 KB
testcase_10 AC 2 ms
5,376 KB
testcase_11 AC 2 ms
5,376 KB
testcase_12 AC 2 ms
5,376 KB
testcase_13 AC 2 ms
5,376 KB
testcase_14 WA -
testcase_15 AC 2 ms
5,376 KB
testcase_16 AC 11 ms
5,376 KB
testcase_17 AC 18 ms
5,376 KB
testcase_18 AC 46 ms
5,376 KB
testcase_19 AC 57 ms
5,376 KB
testcase_20 AC 59 ms
5,376 KB
testcase_21 AC 39 ms
5,376 KB
testcase_22 WA -
testcase_23 AC 48 ms
5,376 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 > 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(), max(e, abs(dist - e)))) {
            cout << 2 << endl;
            return 0;
        }
    }
    for (const ll o : odd) {
        if (upper_bound(even.begin(), even.end(), dist + o) - lower_bound(even.begin(), even.end(), max(o, abs(dist - o)))) {
            cout << 2 << endl;
            return 0;
        }
    }
    cout << -1 << endl;

    return 0;
}
0