結果

問題 No.602 隠されていたゲーム2
ユーザー yocchiyocchi
提出日時 2017-12-17 18:02:11
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 22 ms / 2,000 ms
コード長 1,349 bytes
コンパイル時間 884 ms
コンパイル使用メモリ 71,556 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-22 05:41:04
合計ジャッジ時間 2,121 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 1 ms
4,380 KB
testcase_12 AC 1 ms
4,376 KB
testcase_13 AC 2 ms
4,380 KB
testcase_14 AC 1 ms
4,376 KB
testcase_15 AC 1 ms
4,380 KB
testcase_16 AC 5 ms
4,380 KB
testcase_17 AC 8 ms
4,376 KB
testcase_18 AC 18 ms
4,380 KB
testcase_19 AC 22 ms
4,376 KB
testcase_20 AC 21 ms
4,376 KB
testcase_21 AC 14 ms
4,376 KB
testcase_22 AC 15 ms
4,376 KB
testcase_23 AC 16 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#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