結果

問題 No.602 隠されていたゲーム2
ユーザー mamekin
提出日時 2018-01-12 22:50:40
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 1,231 bytes
コンパイル時間 1,016 ms
コンパイル使用メモリ 103,188 KB
実行使用メモリ 5,248 KB
最終ジャッジ日時 2024-12-24 00:50:42
合計ジャッジ時間 2,916 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 17 WA * 4
権限があれば一括ダウンロードができます

ソースコード

diff #

#define _USE_MATH_DEFINES
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <complex>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
#include <iterator>
using namespace std;

int solve(const vector<int>& v, int dist)
{
    if(dist == 0)
        return 0;
    if(find(v.begin(), v.end(), dist) != v.end())
        return 1;

    int oddMax = -1;
    int evenMax = -1;
    for(int a : v){
        if(a % 2 == 0)
            evenMax = max(evenMax, a);
        else
            oddMax = max(oddMax, a);
    }

    if(dist % 2 == 0){
        if(dist <= max(evenMax, oddMax) * 2)
            return 2;
    }
    else{
        if(oddMax != -1 && evenMax != -1 && dist <= oddMax + evenMax)
            return 2;
    }
    return -1;
}

int main()
{
    int n;
    cin >> n;
    vector<int> v(n);
    for(int i=0; i<n; ++i)
        cin >> v[i];

    int x, y;
    cin >> x >> y;
    int dist = abs(x) + abs(y);

    cout << solve(v, dist) << endl;

    return 0;
}
0