結果

問題 No.602 隠されていたゲーム2
ユーザー fine
提出日時 2017-12-02 19:05:13
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 1,284 bytes
コンパイル時間 1,727 ms
コンパイル使用メモリ 174,204 KB
実行使用メモリ 22,272 KB
最終ジャッジ日時 2024-11-28 03:39:58
合計ジャッジ時間 3,221 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 17 WA * 4
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

using ll = long long;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    set<ll> s;
    for (int i = 0; i < n; i++) {
        ll d;
        cin >> d;
        s.insert(d);
    }
    ll x, y;
    cin >> x >> y;
    ll dist = abs(x) + abs(y);
    int ans = -1;
    if (dist == 0) {
        ans = 0;
    } else if (s.find(dist) != s.end()) {
        ans = 1;
    } else {
        for (ll v : s) {
            if (s.find(dist - v) != s.end()) ans = 2;
            if (s.find(v + dist) != s.end()) ans = 2;
        }

        set<ll> s2, s3;
        for (ll v : s) {
            if (v >= abs(x)) s2.insert(v - abs(x));
            if (v >= abs(y)) s3.insert(v - abs(y));
        }
        for (ll v : s2) {
            if (s3.find(v) != s3.end()) ans = 2;
        }

        if (dist % 2 == 0) {
            if (*s.rbegin() * 2 >= dist) ans = 2;
        } else {
            set<ll> so, se;
            for (ll v : s) {
                if (v % 2 == 0) se.insert(v);
                else so.insert(v);
            }
            if (se.size() > 0 && so.size() > 0) {
                if (*se.rbegin() + *so.rbegin() >= dist) ans = 2;
            }
        }
    }
    cout << ans << endl;
    return 0;
}
0