結果

問題 No.602 隠されていたゲーム2
コンテスト
ユーザー yocchi
提出日時 2017-12-17 18:02:11
言語 C++11
(gcc 15.2.0 + boost 1.89.0)
コンパイル:
g++-15 -O2 -lm -std=gnu++11 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 15 ms / 2,000 ms
コード長 1,349 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 800 ms
コンパイル使用メモリ 92,716 KB
実行使用メモリ 6,400 KB
最終ジャッジ日時 2026-05-26 06:30:42
合計ジャッジ時間 1,510 ms
ジャッジサーバーID
(参考情報)
judge3_1 / judge1_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 21
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <map>
#include <vector>
#include <algorithm>
#include <iostream>

using namespace std;
#define PRINT(x) { std::cout << #x << ": " << x << std::endl; }
//#define PRINT(x)

int main(int argc, char *argv[])
{
    int n;
    scanf("%d", &n);
    vector<int> d(n);
    for (int i = 0; i < n; ++i)
    {
        scanf("%d", &d[i]);
    }
    int x, y;
    scanf("%d %d", &x, &y);
    if (x == 0 && y == 0)
    {
        puts("0");
        return 0;
    }

    int D = abs(x) + abs(y);
    vector<int>::iterator match_D = find(d.begin(),
                                    d.end(),
                                    D);
    if (match_D != d.end())
    {
        puts("1");
        return 0;
    }

    if (D % 2 == 0)
    {
        int max_d = *max_element(d.begin(), d.end());
        puts((2 * max_d >= D) ? "2" : "-1");
        return 0;
    }
    else
    {
        sort(d.begin(), d.end());
        int odd = -1, even = -1;
        for (int i = 0; i < n; ++i)
        {
            if (d[i] % 2 == 0) odd = d[i];
            else even = d[i];
            if (odd == -1 || even == -1) continue;
            if (abs(odd - even) <= D && D <= odd + even)
            {
                puts("2");
                return 0;
            }
        }
    }
    puts("-1");
    return 0;
}
0