結果

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

ソースコード

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;
        }
    }
    cout << ans << endl;
    return 0;
}
0